Should there be a definition for Base dtor?

后端 未结 3 1772
半阙折子戏
半阙折子戏 2021-01-23 16:42

Compiler is giving link error and require to provide definition for Base pure virtual destructor.

class Base
{
public:
    virtual ~Base() = 0;
};

class Derived         


        
3条回答
  •  不思量自难忘°
    2021-01-23 17:10

    Since Derived inherits Base, destroying a Derived object will first call Derived::~Derived and then Base::~Base (the compiler does this for you - whether you like it or not).

    Hence, you have to provide an implementation for Base::~Base. Note that this isn't particularly strange. A pure virtual function can have an implementation. 'pure virtual' only means that the class cannot be instantiated.

提交回复
热议问题