Advertisement

析构函数与多态性的问题所在

阅读量:

在学习虚函数相关知识的过程中,出现了一个疑问。关于析构函数多态性的实现,在特定情况下并不需要将其声明为虚函数。以下为相关代码示例:

复制代码
    #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() 

全部评论 (0)

还没有任何评论哟~