dimanche 29 avril 2018

Inheritance of a Pure Virtual Function

Could somebody please clear these concepts and answer these questions. Thank you in advance.

Class A is a base class and has a pure virtual function named display.

Class A 
{ 
  public:
       virtual void display()const=0;

};

Class B is a derived class that inherits the A class. Furthermore, B overrides the display function,

Class B:public A 
{ 
  public:
       void display()const{cout<<"Always"<<endl;}

};

Q1: Now B contains 1 overridden display and 1 inherited pure virtual display, right? Or does the pure virtual one become non-existent due to the override.

I'm asking this because the ultimate question I'm facing is this: Q2: Suppose B did override the display function, Now, if there a new class

Class C:public B 
{ 
  public:
};

Now, I'm clear on the concept that the all the first level derived classes (like B) have a must on them that they override the pure virtual function(coming from the class A), suppose that they do override it, now what if the there is a new class C that is derived from one of the first-level-derived classes ( class B ), will it also need to override the pure virtual function (display) or will it be not required as it was overridden in the class B and C inherits B(consequently receiving an override of the the display function?

Aucun commentaire:

Enregistrer un commentaire