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

后端 未结 5 2039
暗喜
暗喜 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 02:02

    By making a function pure virtual we force the user of the class to replace the function with another in the derived class.

    The base class function can still be called with BaseClass::myfunction(...)

    Now the base class might want to provide some core functionality that the derived class may use if it chooses to do so.

提交回复
热议问题