虚函数和虚基类混合的情况

class A {
public:
	char k[3];
	virtual void aa() {}
};

class B0 : public  A {
public:
	char j[3];
	virtual void aa() {}
};

class B1 : public A {
public:
	char j[3];
	virtual void aa() {}
	virtual void bb() {}
};

class B2 : virtual public A {
public:
	char j[3];
	virtual void aa() {}
};

class B3 : virtual public A {
public:
	char j[3];
	virtual void aa() {}
	virtual void bb() {}
};

int main() {
	cout << sizeof(A) << " " << sizeof(B0) << " " << sizeof(B1) << " " << sizeof(B2) << " " << sizeof(B3) << endl;
	system("pause");
};


运行结果:



你可能感兴趣的:(C++,虚函数,sizeof,虚继承)