?????????class B???С??12bytes

???????????


class A
{
    int a;
};
class B
{
    int b;
};

class C
{
};
class D
{
};
class E: public virtual A ?? public virtual B ?? public virtual C ?? public virtual D
{
};
void main()
{
    cout<<"sizeof E: "<<sizeof(E)<<endl;      //
}
 


????Class?????????????virtual base class subobjects????????????????:????????????????????.???????е??????????????????????????й????offset(??object????????)????????????????????????????????????????????????virtual base class subobject?????????????????λ????????ε????????????б仯?????????????????????????????????????????????????????????????????????????????????derived class?????????????????乲?????.????????м?????????????:?????????Class???????????????????????????????????沼???

?????????????????????

????class E???С??????е?????????????????


cl test.cpp /d1reportSingleClassLayoutE

?????????????????????????classE????????У???????????е????????????????????????????????Сint a??b ??????8 bytes??????????????VC++????????????麯???????С??????У?????????????и???????????????????


E::$vbtable@:
1>   0 | 0
1>   1 | 4 (Ed(E+0)A)
1>   2 | 8 (Ed(E+0)B)
1>   3 | 12 (Ed(E+0)C)
1>   4 | 16 (Ed(E+0)D)


??????????vbtable??????????棬????vbtable(virtual base class table)??????????????????????м????vbtable??????????4???E??vbtable???????A?????????????????8??12??16????????????????????????vbtable???????????????????????E?????????л????????????