在学习虚函数时,遇到了一个问题。析构函数多态的实现,在一定条件下不需要设定为虚函数。代码如下:
#include<iostream>
using namespace std;
class base {
public:
base() {
cout << "base is running" << endl;
}
~base() {
cout << "base is destroying" << endl;
}
virtual void shut() {
cout << "base is shuting" << endl;
}
virtual void paint() = 0;
virtual int shoot() = 0;
};
class man : public base {
public:
man() {
cout << "man is running " << endl;
}
~man() {
cout << "man is destroying" << endl;
}
void shut() {
cout << "the man is shuting" << endl;
}
void paint() {
cout << "man is painting" << endl;
}
int shoot() {
return (1);
}
};
class woman : public base {
public:
woman() {
cout << "woman is running" << endl;
}
~woman() {
cout