//多重继承 #include <iostream> using namespace std; class A { public: A() { cout<<"A基类构造A::A()"<<endl; } ~A() { cout<<"A基类析构A::~A()"<<endl; } }; class B:public A { public: B() { cout<<"B子类构造B:B()"<<endl; } ~B() { cout<<"B子类析构B:~B()"<<endl; } }; class C:public A { public: C() { cout<<"C子类构造C::C()"<<endl; } ~C() { cout<<"C子类析构C::~C()"<<endl; } }; class D:public B,public C { public: D() { cout<<"D孙子类构造D::D()"<<endl; } ~D() { cout<<"D孙子类析构D::~D()"<<endl; } }; int main(int argc, char *argv[]) { D d; return 0; }
则可以看出构造顺序A->B->A->C-D;析构顺序相反。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。