#include<iostream> using namespace std; //虚函数和析构函数需要定义,否则 //a missing vtable usually means the first //non-inline virtual member function has no definition. class a{ virtual void func(){}; public: virtual ~a()=default;//析构函数需要为public }aObj; class b :public virtual a{ virtual void foo(){}; public: virtual ~b()=default; }bObj; class ax{ virtual void func(){}; char x; public: virtual ~ax()=default; }axObj; class bx:public virtual ax{ virtual void foo(){}; public: virtual ~bx()=default; }bxObj; class c{ virtual void func(){}; public: virtual ~c()=default; }cObj; class d :public c{ virtual void foo(){}; public: virtual ~d()=default; }dObj; class cx{ virtual void func(){}; public: virtual ~cx()=default; char x; }cxObj; class dx:public cx{ virtual void foo(){}; public: virtual ~dx()=default; }dxObj; int main(){ cout<<"aObj "<<sizeof(aObj)<<endl; cout<<"bObj "<<sizeof(bObj)<<endl; cout<<"axObj "<<sizeof(axObj)<<endl; cout<<"bxObj "<<sizeof(axObj)<<endl; cout<<"cObj "<<sizeof(cObj)<<endl; cout<<"dObj "<<sizeof(dObj)<<endl; cout<<"cxObj "<<sizeof(cxObj)<<endl; cout<<"dxObj "<<sizeof(dxObj)<<endl; return 0; } //clang3.8 gcc7.1 //aObj 8 //bObj 8 //axObj 16 //bxObj 16 //cObj 8 //dObj 8 //cxObj 16 //dxObj 16