一、问题提出
定义一个基类BassClass,从他派生出类DerivedClass.在BaseClass中声明虚析构函数,,在主函数中将一个动态分配的DerivedClass的对象地址赋给一个bassClass的指针,然后通过指针释放对象空间,观察运行结果。
代码实现。
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;
class BaseClass
{
public:
virtual ~BaseClass();
};
class DerivedClass :public BaseClass
{
public:
~DerivedClass();
};
BaseClass::~BaseClass()
{
cout << "BaseClass 析构" << endl;
}
DerivedClass::~DerivedClass()
{
cout << "DerivedClass 析构" << endl;
}
int main()
{
BaseClass *BP = new DerivedClass;
delete BP;
}
标签:函数,虚析构,DerivedClass,include,BaseClass,public From: https://www.cnblogs.com/luoqingci/p/17351171.html