#include<stdio.h> #include<iostream> using namespace std; class base1{ public: base1(){ printf("start base1\n"); } ~base1(){ printf("end base1\n"); } private: int mx,my; int mi,mj; }; class base2:public base1{ public: base2(){ printf("start base2\n"); } ~base2(){ printf("end base2\n"); } private: int mx,my; int mi,mj; }; class base3:public base2{ public: base3(){ printf("start base3\n"); } ~base3(){ printf("end base3\n"); } private: int mx,my; int mi,mj; }; int main(){ base3 *temp1=new base3; delete temp1; }
可以明显的看到构造的时候,从基类开始逐渐到当前类
而析构的过程是,从当前类逐渐到基类