0
class abstract 
{double abs; };

class A : virtual public abstract
{ double var; };

class B : virtual public abstract
{ double var; };

class derived : public A, public B
{ double der; };

sizeof(abstract) = 8

sizeof(A) = 24

sizeof(B) = 24

sizeof(derived) = 48

Why does this happen?

(Note: On the contrary without the virtual classes the sizes returned are 8, 16, 16, 40 respectively. )

Community
  • 1
  • 1
Level 31
  • 403
  • 3
  • 9
  • 2
    **Probably** (but it's implementation defined) they're to keep track (point to) virtual base class. See also [this post](http://stackoverflow.com/questions/9737847/multiple-inheritance-size-of-class-for-virtual-pointers/9737936#9737936). – Adriano Repetti Jul 10 '14 at 15:18

1 Answers1

0

It requires the type to store more information to facilitate virtual behavior.

wbennett
  • 2,545
  • 21
  • 12