Do ALL virtual functions need to be implemented in derived classes?

后端 未结 5 1126
猫巷女王i
猫巷女王i 2020-11-30 18:44

This may seem like a simple question, but I can\'t find the answer anywhere else.

Suppose I have the following:

class Abstract {
public:
    virtual          


        
5条回答
  •  甜味超标
    2020-11-30 19:42

    Yes, Its correct that a Derived class has to OVERRIDE the function which is Pure Virtual in the Parent Class. Parent class having a Pure Virtual Function is called Abstract Class only because it's Child class must give their own body of the Pure Virtual Function.

    For the Normal Virtual Functions:- Its not necessary to override them further, as some child class may have that function, some may not have.

    Main purpose of Virtual Function mechanism is Run Time Polymorphism, whether main purpose of Pure Virtual Function(Abstract Class) is to make it mandatory to have the same name Function with own's body.

提交回复
热议问题