Virtual/pure virtual explained

后端 未结 12 1464
暖寄归人
暖寄归人 2020-11-22 01:31

What exactly does it mean if a function is defined as virtual and is that the same as pure virtual?

12条回答
  •  逝去的感伤
    2020-11-22 02:22

    A virtual function is a member function that is declared in a base class and that is redefined by derived class. Virtual function are hierarchical in order of inheritance. When a derived class does not override a virtual function, the function defined within its base class is used.

    A pure virtual function is one that contains no definition relative to the base class. It has no implementation in the base class. Any derived class must override this function.

提交回复
热议问题