#include <iostream>
using namespace std;
class A
{
public:
int val;
char c1;
};
class B: public A
{
public:
char c2;
};
class C: public B
{
public:
char c3;
};
int main()
{
cout << sizeof(A) << ", " << sizeof(B) << ", " << sizeof(C) << endl;
return 0;
}
输出为8,12,12。 B的大小为12,因为在A :: c1之后有3个字节的填充。但为什么C的大小也是12? Aren在B :: c2之后有字节填充吗? (我使用的编译器是gcc 4.8)