TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  INT#027Checked automatically with code checker

Synopsis:If you override one of the base class's virtual functions, then you shall use the "override" or "final" keyword
Severity Level:2
Category:Class Interface


It is not possible to remove the virtual-ness of an inherited virtual function: any virtual function overrides itself. This rule makes explicit that the function that overrides a virtual function is virtual too, which it would also have been if the overriding function were not declared as such.

By adding the "override" keyword you express your intention that this function is an override of a function in the parent class. This is also checked by the compiler. If you make a mistake (see example below) the compiler will issue an error to indicate that the function doesn't override another function:

class base
    virtual int foo(float x) = 0; 

class derived: public base
     virtual int foo(float x) { ... } // before C++11, not accepted any more
     int foo(float x) override { ... } // C++11

class derived2: public base
     int foo(int x) override { ... }  // won't compile!