Description: The override reserved word indicates that the current function overrides the virtual function of the base class.
Objective: 1. In the case of more functions, you can prompt the reader that a function overrides the base class virtual function (which means that the virtual function is inherited from the base class, not the derived class itself); 2. Forces the compiler to check whether a function overrides the base class virtual function, and if not, an error.
Usage: Add the keyword after the member function parameter list of the class.
Example:
Class Base {
virtual void f ();
};
Class Derived:public Base {
void f () override; Represents a derived class overriding the base class virtual function f
void f () override;//error: Function F does not override any virtual function of base class
};
Note: Override is only a C + + reserved word, not a keyword, which means that only the correct use of the location, oerride the "keyword" function, other places can be used as a marker (such as: int override; is legal).
Related: Override also has a sister reserved word final.
C + + override keyword