Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make implementation of virtuals also virtual?

When implementing a pure virtual function in C++, is there a best-practices guideline that says the implementation should also be made virtual? What is the rationale?

class Interface
{
  public:
    virtual void foobar() = 0;
};

class Concrete
    : public Interface
{
  public:
    virtual void foobar();
};
like image 316
Paul Manta Avatar asked Nov 30 '22 08:11

Paul Manta


1 Answers

It does not matter.

void foobar() in Concrete is virtual regardless whether you declare it as such and it overrides the void foobar() in Interface.

like image 71
James McNellis Avatar answered Dec 04 '22 12:12

James McNellis