in c++ when subclassing why sometimes need to add virtual keyword to overridden function?
Why do I sometimes see in C++ examples when talking about subclassing / inheritance, the base class has virtual keyword and sometimes the overridden function has also the virtual keyword, why it's necessary to add to the subclass the virtual key word sometimes? For example: class Base { Base(){}; virtual void f() ...... } }; class Sub : public Base { Sub(){}; virtual void f() ...new impl of f() ... } }; It is not necessary, but it helps readability if you only see the derived class definition. §10.3 [class.virtual]/3 If a virtual member function vf is declared in a class Base and in a class