1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
| class A {
}; class B : virtual public A { }; class C : virtual public A { }; class D : public B, public C { }; int main(void) { cout << sizeof(A) << endl; //1 cout << sizeof(B) << endl; //4 cout << sizeof(C) << endl; //4 cout << sizeof(D) << endl; //8 return 0; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
| class A { int a; }; class B : virtual public A { }; class C : virtual public A { }; class D : public B, public C { }; int main(void) { cout << sizeof(A) << endl; //4 cout << sizeof(B) << endl; //8 cout << sizeof(C) << endl; //8 cout << sizeof(D) << endl; //12 A的int 4Byte,B C虚继承指针4+4,共12Byte.
return 0; }
|
转载于:https://www.cnblogs.com/helloweworld/archive/2013/06/14/3135218.html