Override identifier after destructor in C++11

后端 未结 2 1766
不思量自难忘°
不思量自难忘° 2021-01-30 06:50

Does the override identifier after virtual destructor declaration have any special meaning?

class Base
{
public:
    virtua         


        
2条回答
  •  梦如初夏
    2021-01-30 07:14

    Yes. If the base destructor is not virtual then the override marking will cause the program to not compile:

    class Base
    {
    public:
        ~Base()
        {}
    };
    
    class Derived : public Base
    {
    public:
        virtual ~Derived() override //error: '~Derived' marked 'override' but does
                                    //        not override any member functions
        {}
    };
    

提交回复
热议问题