自考新教材-p263

不使用虚析构函数的情况

源程序:

#include <iostream>

using namespace std;

class ABase{

public:

ABase(){

cout<<"ABase构造函数"<<endl;

}

~ABase(){

cout<<"ABase::析构函数"<<endl;

}

};

class Derived:public ABase{

public:

int w,h;

Derived(){

cout<<"Derived构造函数"<<endl;

w = 4;

h = 7;

}

~Derived(){

cout<<"Derived::析构函数"<<endl;

}

};

int main(){

ABase *p = new Derived();

delete p;

return 0;

}

运行结果:

posted @ 2020-01-12 18:10  bobo哥  阅读(188)  评论(0编辑  收藏  举报