Override

The override specifier was added in C++11 and is used to show that a method is overriding another method in a base class. When you use this specifier the compiler will help you to make sure that you are using the same signature in the new method as in the base class method.

Examples:

 

Why should we use this?

 

  • Because this makes your code more clear, adding override to your function makes it clear to anyone reading the code later that this is an override of a base class function.
  • It is very easy to accidentally create a new virtual function in a derived class when you intended to override a function in a base class by making an error in the signature of the function (like forgetting a const).
Facebookgoogle_pluslinkedinmail