Overload, override and overwrite
Overload: In C ++ProgramIn, several functions with similar semantics and functions can be represented by the same name, but the parameters or return values are different (including different types and sequences), that is, function overloading.
(1) the same range (in the same class );
(2) The function name is the same;
(3) parameters are different;
(4) virtual keywords are optional.
Override (overwrite): refers to the function of the derived class that overwrites the base class function. The features are as follows:
(1) different scopes (located in the derived class and the base class respectively );
(2) The function name is the same;
(3) The parameters are the same;
(4) basic functions must have virtual keywords.
Overwrite: the function of the derived class shields the base class functions with the same name. The rules are as follows:
(1) If the function of the derived class has the same name as the function of the base class, but the parameter is different. At this time, no matter whether there is a virtual
Keyword, the function of the base class will be hidden (note not to be confused with the overload ).
(2) If the function of the derived class has the same name and parameter as the function of the base class, but the base class function does not have the virtual
Keyword. In this case, the function of the base class is hidden (do not confuse with overwrite ).
-- That is, When overwrite is used, if the base class uses the virtual keyword, the base class function will not
Hide.
If the base class has multiple overload versions of a function, and you overwrite one of them in the subclass, or add a new function version to the subclass, the overloaded versions of all base classes are masked. Therefore, in normal cases, all the overloaded versions in the base class should be overwritten in the subclass.
Specifically, the overload and rewriting of the inheritance class both contain the meaning of rewriting, that is, as long as the function name is the same, the function version of the base class will be masked, to maintain the base class's overloaded version in the derived class, you should
Override the overloaded versions of all base classes. Overloading is only valid in the current class. inheritance will lose the feature of overloading. That is to say, to put the base class overload function in the inheritance class, it must be rewritten.