自考新教材-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;

}

运行结果:

猜你喜欢

转载自www.cnblogs.com/duanqibo/p/12183360.html