its two ints from X and Y classes :8 2 copies of int from Base class via Class X and Class Y :8
surender On Tue, Jul 5, 2011 at 10:39 PM, oppilas . <[email protected]>wrote: > @T3rminal > Then how would you explain size of Z in case of normal inheritance( > sizeof(Z)=16 > > On Mon, Jul 4, 2011 at 4:08 AM, T3rminal <[email protected]> wrote: > >> @abc abc >> 4th class= two ints from X and Y classes + one int from base class( as >> this class is shared ) + 2 virtual pointers of X and Y classes. >> > According to your logic it should be 12 > >> >> On Jul 3, 2:24 pm, abc abc <[email protected]> wrote: >> > In the second case , the size of vptr will be added to each and every >> object >> > . >> > 1st class = one int :4 >> > 2nd class = one int +one int from base + vptr =12 >> > 3rd class = one int + one int from base + vptr =12 >> > 4th class =one int from each base class + one int from each of the grand >> > parent +one vptr =20 >> > >> > On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal < >> [email protected] >> > >> > >> > >> > >> > >> > >> > >> > > wrote: >> > > class Base >> > > { >> > > public: >> > > int a; >> > > }; >> > >> > > class X: public Base >> > > { >> > > public: >> > > int x; >> > > }; >> > >> > > class Y: public Base >> > > { >> > > public: >> > > int y; >> > > }; >> > >> > > class Z:public X,public Y >> > > { >> > > }; >> > >> > > int main() >> > > {cout<<sizeof(Base)<<endl; >> > > cout << sizeof(X) <<endl; >> > > cout << sizeof(Y) <<endl; >> > > cout << sizeof(Z) <<endl; >> > > } >> > > o/p is 4 >> > > 8 >> > > 8 >> > > 16... >> > > which is absolutely fine..... >> > >> > > but the problem arises here.... >> > > class Base >> > > { >> > > public: >> > > int a; >> > > }; >> > >> > > class X:virtual public Base >> > > { >> > > public: >> > > int x; >> > > }; >> > >> > > class Y:virtual public Base >> > > { >> > > public: >> > > int y; >> > > }; >> > >> > > class Z:public X,public Y >> > > { >> > > }; >> > >> > > int main() >> > > {cout<<sizeof(Base)<<endl; >> > > cout << sizeof(X) <<endl; >> > > cout << sizeof(Y) <<endl; >> > > cout << sizeof(Z) <<endl; >> > > } >> > >> > > o/p is 4 >> > > 12 >> > > 12 >> > > 20 >> > > why the size is 12 and 20 for x and Z....does this is because that >> > > some sort of VPTR IS maintained in the class....if yes then then what >> > > does that points to.... >> > >> > > PS:HERE.....i am talking about virtual inheritance....NOT ABOUT >> > > "VIRTUAL FUNCTIONS"... >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> Groups >> > > "Algorithm Geeks" group. >> > > To post to this group, send email to [email protected]. >> > > To unsubscribe from this group, send email to >> > > [email protected]. >> > > For more options, visit this group at >> > >http://groups.google.com/group/algogeeks?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
