Purpose of making overridden virtual function non-virtual
c++, c++11, inheritance, overriding, virtual-functions
Solution
An override of a virtual function is always virtual regardless of whether it's declared as such. Thus, having or not having the `virtual` keyword in the declaration of `Sub2::foo()` has no effect whatsoever as far as the language is concerned, since the `override` keyword means that the function must override a member function of a base class. From §10.3 [class.virtual]/p2 of the standard, emphasis added:
If a virtual member function `vf` is declared in a class `Base` and in a class `Derived`, derived directly or indirectly from `Base`, a member function `vf` with the same name, parameter-type-list (8.3.5), cv-qualification, and ref-qualifier (or absence of same) as `Base::vf` is declared, then `Derived::vf` is also virtual (whether or not it is so declared) and it overrides `Base::vf`. For convenience we say that any virtual function overrides itself.
Problem
Consider the following classes in C++11: ``` class Base { public: virtual void foo() = 0; } class Sub1 : public Base { public: virtual void foo() override {}; } class Sub2 : public Base { public: void foo() override {}; } ``` What are the consequences of making the overridden function non-virtual as in `Sub2`?