Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following C++ class decarations: class B { private: int x; public: virtual int foo() { return this->bar(); } virtual int bar() { return

image text in transcribedGiven the following C++ class decarations:

 class B { private: int x; 
 public: virtual int foo() { return this->bar(); } virtual int bar() { return 1; } 

};

 class C { private: int x; 
 public: virtual int foo() { return 2; } 

};

 class D : public B, public C { private: 
 int y; public: 
 virtual int foo() { return B::foo(); } }; 
 class E : public D { private: 
 int z; public: 
 virtual int bar() { return 3; } }; 

Show the layout of objects of class E and the contents of the virtual function tables (you can ignore the this-offsets). What are the values assigned to variables i, j, k, and l when the following code is executed?

 B * p = new D(); C * q = new D(); B * r = new E(); C * s = new E(); int i = p->bar(); int j = q->foo(); int k = r->bar(); int l = s->foo(); 

4. (25 pts) Given the following C++ class declarations class B { private: int x; public: virtual int foo)return this->bar); ) virtual int bar() 1 return 1; 1 class C f private: int x; public: virtual int foo) return 2; } class D : public B, public C private: int y; public: virtual int foo)return B::foo(): class E : public D i private: int z public: virtual int bar() f return 3; > Show the layout of objects of class E and the contents of the virtual function tables (you can ignore the this-offsets). What are the values assigned to variables i, j, k, and 1 when the following code is executed? B* p new D); C * g = new D(); B * r -new E); c * s new E(); int i = p->bar(); int j = g->foo( ) ; int k = r->bar(); int 1 s->foo()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

Students also viewed these Databases questions

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago