虚继承涉及虚表(虚指针),所以sizeof(C) = 8
1 #include <iostream> 2 using namespace std; 3 4 class A{}; 5 class A2{}; 6 class B:public A 7 {}; 8 9 class C:public virtual B 10 {}; 11 12 class D:public A,public A2 13 {}; 14 15 int main(int argc,char *argv[]) 16 { 17 cout << "sizeof(A)" << sizeof(A) <<endl;//1 18 cout << "sizeof(B)" << sizeof(B) <<endl;//1 19 cout << "sizeof(C)" << sizeof(C) <<endl;//8 20 cout << "sizeof(D)" << sizeof(D) <<endl;//1 21 return 0; 22 23 }
标签:多重,int,占用,class,继承,A2,空类,public From: https://www.cnblogs.com/xhu218/p/16894058.html