代码:
#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;
}
运行结果:
XY
Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.
总结:
自动调用相应虚析构函数以释放内存 还是调用该类族所有的析构函数?