Search code examples
c++interfacemethodsvirtual

Should methods that implement pure virtual methods of an interface class be declared virtual as well?


I read different opinions about this question. Let's say I have an interface class with a bunch of pure virtual methods. I implement those methods in a class that implements the interface and I do not expect to derive from the implementation.

Is there a need for declaring the methods in the implementation as virtual as well? If yes, why?


Solution

  • No - every function method declared virtual in the base class will be virtual in all derived classes.

    But good coding practices are telling to declare those methods virtual.