虚析构函数
关于虚析构函数的一个疑问:
#include <iostream.h>
class Base
{
public:
virtual ~Base() { cout<< "~Base" << endl ; }
};
class Derived : public Base
{
public:
virtual ~Derived() { cout<< "~Derived" << endl ; }
};
void main(void)
{
Base * pB = new Derived; // upcast
delete pB;
}
输出结果为:
~Derived
~Base
问题是:
如果析构函数不为虚,输出结果为:
~Base
请问这是为什么?这与析构的次序问题有什么本质的区别?