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.