#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; }
运行结果:
先析构派生类对象 后析构基类对象
时间: 2024-10-12 22:03:25