1、虚继承中对象占用的内存空间1
#include <iostream>
using namespace std;
class AA
{
void show() {}
int max(int a, int b) { return a > b ? a : b; }
};
class A
{};
class B
{
int c;
};
class C :virtual public A
{};
int main()
{
cout << sizeof(AA) << endl;
cout << sizeof(A) << endl;
cout << sizeof(B) << endl;
cout << sizeof(C) << endl;
return 0;
}
2、虚继承中对象占用的内存空间1
#include <iostream>
using namespace std;
class Base
{ virtual void show(){} };
class Derived1 : public Base
{};
class Dervied2 : public Base
{ virtual void show2() {} };
class Dervied3 : public virtual Base
{ virtual void show3() {} };
int main()
{
cout << sizeof(Base) << endl;
cout << sizeof(Derived1) << endl;
cout << sizeof(Dervied2) << endl;
cout << sizeof(Dervied3) << endl;
return 0;
}