c++中类实例化时候对基类的调用顺序

来源:互联网 发布:网络系统安全技术的有 编辑:程序博客网 时间:2024/04/27 19:05
#include<iostream>using namespace std;class A{public:A(){cout<<"this is the construct of A"<<endl;}~A(){cout<<"this is the destruct of A"<<endl;}};class B:public A{public:B(){cout<<"this is the construct of B"<<endl;}~B(){cout<<"this is the destruct of B"<<endl;}};class c:public B{public:c(){cout<<"this is the constrcut of c"<<endl;}~c(){cout<<"this is the destruct of c"<<endl;}private:A _a;1};int main(){c C;return 0;}

输出顺序如下:

this is the construct of A

this is the construct of B
this is the construct of A
this is the constrcut of c
this is the destruct of c
this is the destruct of A
this is the destruct of B
this is the destruct of A


0 0
原创粉丝点击