Why does it make sense to give definition for a pure virtual function?

后端 未结 5 2020
暗喜
暗喜 2020-12-31 01:44

Scott said on Effective C++, 3rd Edition, pg. 43 that to make an abstract class, we just need to give it a pure virtual destructor:

class AWOV {                      


        
5条回答
  •  一整个雨季
    2020-12-31 01:54

    This is not necessary for all pure virtual functions. Not at all.

    This way, the derived classes will still be forced to override the implementation, but there will be a default implementation in the base class, in case you need to call it. And that's the case here - because you're dealing with a destructor: when a derived object is being destroyed, its destructor is called and its base classes destructors are called as well. That's why you need an implementation for A::~A.

提交回复
热议问题