In the code below, 'a' and 'r[0]' both refer to the same object (correct me if that is wrong).
sizeof(a) is 12 while sizeof(r[0]) is 1; why are they not the same size?
#include <iostream>
usingnamespace std;
class Base
{
};
class A: public Base
{
int x;
int y;
int z;
};
class B: public Base
{
};
int main()
{
A a;
B b;
// output:
cout << sizeof(a) << endl; // 12
cout << sizeof(b) << endl; // 1
Base r[] = {a, b};
cout << sizeof(r[0]) << endl; // 1
cout << sizeof(r[1]) << endl; // 1
}