In your subclass, BB is a virtual subclass of A. Thus, B has a separate vtbl pointer (4 bytes) on top of what you have on subobject A. Thus,
sizeof(B object) = sizeof(A object) + sizeof (vtbl pointer of B) = sizeof(int) + sizeof (vtbl pointer of A) + sizeof (vtbl pointer of B) = 4 + 4 + 4 = 12
AND,
sizeof(A object) = sizeof(int) + sizeof (vtbl pointer of A) = 4 + 4 = 8
If B is a normal subclass of A,
sizeof(B object) = sizeof(A object) = sizeof(int) + sizeof (vtbl pointer of A) = 4 + 4 = 12
For an empty class A, the minimum size allocated to the sizeof A object is a size pointer vtbl = 4 And since A is empty in terms of instance data, virtual inheritance for an empty class does not add to the size of the object
source share