I have the following code about object sizes:
class A
{
public:
int _i;
virtual int getI () = 0;
int setI (int i);
};
class B : public A
{
public:
int getI ();
virtual int setI (int i);
};
class C : public B
{
public:
int _i;
int getI ();
int setI (int i);
};
int main ()
{
B b;
C c;
}
Why the size of
C c;
is 12? What parts included in the size calculation?
sizeof(int A::_i) + sizeof(int C::_i) + sizeof(pointer to virtual table)The size of all these parts is implementation-dependent, in your case, each one has size 4.