1、原因:
在实现多态时, 当用基类指针操作派生类, 在析构时候防止只析构基类而不析构派生类。
2、例子:
(1)、
#include<iostream>
using namespace std;
class Base{
public:
Base() {};
~Base() {cout << Output from the destructor of class Base! << endl;};
void DoSomething() { cout << Do something in class Base! << endl;