c++ - Existence of VPTR in subobjects -


i have class 'base' virtual destructor , vtable , corresponding vtpr in it, , class derived it:

class base { public:     virtual ~base() {} };  class der : base {};  main() {      int = sizeof(base); // = 4 , fine !      int b = sizeof(der);  // = 4 ? } 

now derived class virtual, it'll have vptr of own, since has subobject of base class vptr in it, shouldn't size of class 'der' 8 bytes i.e. size of vptr of class 'der' + size of vptr of subobject of class 'base'? (when sizeof(void*) = 4 bytes ).

so question : when subobject of class 'base' made in 'der' have seperate new vptr ? , if why size not getting added while calculating size of 'der'?

can please clarify this.

this implementation-specific. in practice, there 1 vptr in derived class; there no need two. whole point of vptr it's gets used dynamically call correct override of virtual function; der objects have different pointer value base objects.

[note: example confused fact (unintentionally?) using private inheritance, rather more typical public inheritance...]


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -