对于派生类的构造函数,定义对象时构造函数的执行顺序为 2->1->3
1、成员对象构造函数
2、基类构造函数
3、派生类本身构造函数
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout<<"The constructor of A"<<endl;
}
};
class C
{
public:
C()
{
cout<<"The constructor of C"<<endl;
}
};
class B:public A
{
C member_c;
public:
B()
{
cout<<"The constructor of B"<<endl;
}
};
int main(void)
{
B member_b;
system("pause");
return 0;
}