Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see three point analysis for the above question</p> <h2>a. Virtual Inheritance <br/></h2> <p>"Virtual inheritance is a mechanism whereby a class specifies that it is willing to share the state of its virtual base class. Under virtual inheritance, only one, shared base-class subobject is inherited for a given virtual base regardless of how many times the class occurs as a virtual base within the derivation hierarchy. The shared base-class subobject is called a virtual base class." ... From Lippman</p> <p>Virtual inheritance only avoids duplicate sub-objects inherited from multiple inheritance. But this does not indicate in any way that the base class objects will not be sub-objects. On the contrary, the sub-object (atleast one copy would be present - I mean would be included in sizeof() operation) even during the virtual inheritance.</p> <h2>b. virtual function <br/></h2> <p>Virtual function is for dynamic binding of member functions of objects involved in hierarchy. So even this does not have any significance towards sub-object arrangements.</p> <h2>c. Implementation of the sub-objects <br/></h2> <p>This is totally compiler dependent, and for all reasons would be very difficult to determine - in its implementation. However, we can confirm that the sizeof() of the object would include the size of the base class (sub) objects also - and we can visualize them as having the base class object embedded in them. </p> <p>Each object of the inherited function will definitely contain space for the sub-objects. </p> <p>HTH </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload