Consider the following program:
#include<iostream>
using namespace std;
class base {
int arr[10];
};
class b1: virtual public base { };
class b2: virtual public base { };
class derived: public b1, public b2 {};
int main(void)
{
cout<<sizeof(derived);
return 0;
}
According to me, the array arr is inherited only once in the class due to virtual base class. Hence sizeof derived class should be 10*4=40 bytes. However, on execution, this program is printing 56 as the output. I even checked the size of int on the compiler, it was 4 bytes only. Can someone explain me where are the additional 16 bytes coming from?