#include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n) {} virtual ~BASE() { cout<<c; } }; class DERIVED:public BASE { private: char c; public: DERIVED(char n):BASE(n+1),c(n) {} ~DERIVED(){ cout<<c; } }; int main(){ DERIVED d('X'); return 0; }
运行结果:
先析构派生类对象 后析构基类对象
原文地址:http://blog.csdn.net/ljd939952281/article/details/46313599