C ++ has four new mechanisms: overload, inline, const, and virtual.
Overload and inline: can be used for global functions or member functions of the class;
Const and virtual: can be used only for class member functions;
Overload: functions with the same name in the same class. The parameter determines which function to call. A function must have virtual keywords. A function with the same name as a global function is not called an overload. If you call a global function with the same name in a class, you must use the global reference symbol: reference.
Overwrite indicates that the function of a derived class overwrites the base class function.
The function name is the same;
The parameters are the same;
Basic functions must have virtual keywords;
Different scopes (derived classes and base classes ).
Hiding means that the derived class shields the Same Name functions of the base class.
1,
The function name is the same, but the parameters are different. In this case, the base class function is hidden regardless of whether the base class has the virtual keyword.
2,
The function name is the same and the parameters are the same, but the base class does not have the virtual keyword (if any). The base class function will be hidden.
Inline: The Inline keyword must be put together with the definition body, rather than just in the Declaration.
Const: const is the abbreviation of constant, which means "constant. All things modified by const are protected by force, which can prevent unexpected changes and improve program robustness.
1,
Parameters are pointer-type parameters used for input. Adding const can prevent unexpected changes.
2,
When the user type referenced by value is used as the input parameter, it is best to change the pass by value to the pass by reference and add the const keyword to improve efficiency. If the data type is internal, there is no need to do this; for example:
Set void func ()
Change to void func (const A & ).
Void func (int A) does not need to be changed to void
Func (const Int & );
3,
If you add a const to a function whose return value is pointer type, the return value of the function cannot be modified. The assigned variable can only be a const type variable. Example: function const
Char * getstring (void); char * STR = getstring () will cause an error. While const
Char * STR = getstring () will be correct.
4,
A const member function is a function that can only call the const member variable to improve the program's key robustness. Such as declaring a function
Int getcount (void) const; this function can only call the const member variable.
Virtual: virtual function: a function that can be overwritten by a derived class. Pure virtual function: it is only an empty function and has no function implementation body;