#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 Bthis 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