#include <stdio.h>
class X
{
};
class Y
{
// long x; // case A)
// X x; // case B)
};
class Z : public Y, public X
{
};
int main() {
Z z;
printf("%d %d %d\n",
sizeof(Z), sizeof(Y), (char*)static_cast<X*>(&z) - (char*)&z);
return 0;
}
Why is the output as follows after uncommenting either case A or case B:
A: 4 4 4
B: 2 1 2
Why is sizeof(Y) != sizeof(Z) in case B), but is equal in case A). Can anyone explain?