/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:舒文超
* 完成日期:2016年4月30日
* 版本号:vc++6.0
* 问题描述:阅读下面程序,并写出运行结果。
*/
#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 *p,d('x');
return 0;
}
运行结果:
xy:在程序运行结束时先运行继承类中的析构函数,再运行基类的析构函数。