年轻人的努力

导航

虚继承

class person
{
public:
int a;
};


class son1: virtual public person
{

};

class son2: virtual public person
{

};

class son: public son1,public son2
{

};

sizeof(虚基类) = 4

sizeof(son1) = 4+4(vbptr指针)

sizeof(son2) = 4+4(vbptr指针)

sizeof(son) = 4+4(son1vbptr指针)+4(son2vbptr指针)

 

posted on 2021-04-16 15:46  年轻人的努力  阅读(35)  评论(0编辑  收藏  举报