有人可以帮助我了解所有数据以及在类对象中存储的顺序是什么?
#include <iostream>
using namespace std;
class A{
public:
A(){}
virtual ~A(){}
};
class B{
public:
B(int i):_i(i){}
~B(){}
private:
int _i;
};
class C{
public:
C(int i):_i(i){}
virtual ~C(){}
private:
int _i;
};
int main()
{
cout << "SIZEOF A : " << sizeof(A) << endl;
cout << "SIZEOF B : " << sizeof(B) << endl;
cout << "SIZEOF C : " << sizeof(C) << endl;
return 0;
}
输出:
SIZEOF A:8 SIZEOF B:4 SIZEOF C:16
为什么Sizeof(C)是16而不是12?