Pure virtual function with implementation

前端 未结 9 2078
长发绾君心
长发绾君心 2020-11-22 10:10

My basic understanding is that there is no implementation for a pure virtual function, however, I was told there might be implementation for pure virtual function.

9条回答
  •  自闭症患者
    2020-11-22 11:04

    To be clear, you are misunderstanding what = 0; after a virtual function means.

    = 0 means derived classes must provide an implementation, not that the base class can not provide an implementation.

    In practice, when you mark a virtual function as pure (=0), there is very little point in providing a definition, because it will never be called unless someone explicitly does so via Base::Function(...) or if the Base class constructor calls the virtual function in question.

提交回复
热议问题