-1

What will be size of a derived class which inherited from 3 base classes and all are empty?

class derived also empty base1 base2 base 3 at base classes at same level and derived class inherited from all three

  1. inheritance is public
  2. inheritance is virtual public

in both class size of a object of derived class??

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084

2 Answers2

0

The standard does not impose an upper limit on the class size. For the lower limit it permits an empty base class to generally be optimized away. However, without checking it more closely, I believe a virtual empty base class can't be optimized away, because the address of that base class subobject needs to be the same in all the virtually derived classes.

To find the specific size with a given compiler and options, use the sizeof operator.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
0

You can use -d1reportAllClassLayout option when you compile to show the memory layout, size of your class

HappyTran
  • 503
  • 6
  • 9