Can anyone explain, why size of the objC is 8, not 12?
I think, that if it in the class C I have object with type int and in A, B - char, then after creation of the objC it should be 4 bytes for objA, objB and ObjC.
class A {
char a;
};
class B : A {
char b;
};
class C : B {
int c;
};
int main()
{
A objA;
B objB;
C objC;
cout << sizeof(objA) << endl; // 1
cout << sizeof(objB) << endl; // 2
cout << sizeof(objC) << endl; // 8! Why not 12?
return 0;
}
Edit 1:
In this case sizeof(objC) will be 12:
class A {
char a;
};
class B : A {
int b; // Here is int
};
class C : B {
char c; // Here is char
};