Size of Derived class, upon virtual base class inheritance

I have the two class definition as follows.


class A { public: int a; };

class B : virtual public A{ };

The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?.

Finally .. I think i got answer !!! its may be because of virtual pointer in the derived class.

Sorry, I was away last week, but that's exactly it.

Making it 'virtual' means the computer needs to store extra information in the class, since it doesn't know what functions to call it it from the type it's supposed to be alone.

1 Like