首先声明
定义了派生类会同时调用基类和派生的构造函数
定义了派生类会同时调用基类和派生的析构函数
那么顺序如何如下图
构造由上往下顺序执行
析构则完全相反
#include "iostream"using namespace std;class base
{public:base(){cout << "base-build" << endl;}~base(){cout << "base-destruct" << endl;}
};class newbase:public::base
{public:newbase(int a,int b){cout << "newbase-build" << endl;}~newbase(){cout << "newbase-destruct" << endl;}
};int main()
{newbase rlxy(1,2);}