Home > database >  In a multi-level inheritance, does a grandchild require to implement a pure virtual method, if its p
In a multi-level inheritance, does a grandchild require to implement a pure virtual method, if its p

Time:02-15

class A {
  public:  virtual void start() = 0;
};

class B : public A {
  public: void start();
};

class Ba : public B {    
};

Do we need to redefine start() in Ba or the parent's B::start() would be enough?

CodePudding user response:

Parent's start() is enough.

You should though use the override keyword for B's reimplementation :

class B : public A {
  public: void start() override;
};

It makes it clear that the method is an implementation of a virtual one and the compiler will enforce that it will always be the case, even with future changes on class A.

CodePudding user response:

First of all ur statement : public: void start(); will be problematic as it is must to override the pure virtual function in derived class otherwise derived class also becomes abstract.

Coming to your actual question B's start would be enough.

  • Related