【发布时间】:2018-10-06 09:17:38
【问题描述】:
GCC/32Bit architecture
class B
{
int x,y;
};
class D1: public virtual B
{
int z;
};
class D2; public virtual B
{
int z;
public:
virtual void func(){}
};
int main() {
B b; D1 d1; D2 d2;
cout<<sizeof(b)<<endl;
cout<<sizeof(d1)<<endl;
cout<<sizeof(d2)<<endl;
return 0;
}
据我了解, B有2个整数:8字节 D1:偏移到 B(B _vPtr), x,y,z => 16。 D2: B _vBase, VPTR, x, y => 16
Ans i am getting is 8, 24, 24.
What is the size of the class and how memory allocated for this classes.
How is Vptr and Vtable managed in these cases.
【问题讨论】:
标签: inheritance virtual