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

Given the following C++ class decarations: class B { private: int x;Given 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!