In a class hierarchy where A
is derived from B
, and C
is derived from A
, all having virtual functions, A
and C
would share the same VPTR as they are in the same class hierarchy. Therefore, the size of C
would be the size of a single VPTR, which is typically 8 bytes on a 64-bit platform.
On the other hand, when a class C
is derived from two parent classes A
and B
, and both A
and B
have a virtual function, C
would have two VPTRs - one for each class hierarchy. Therefore, the size of C
would be the sum of the sizes of the VPTRs for A
and B
, which is typically 16 bytes on a 64-bit platform.