Overwriting and rewriting can be said to be the same, but they are different from overloading.
Override (rewriting) refers to functions in different scopes where multiple function prototypes are exactly the same but the implementation is different. In C++, this often happens with class inheritance. When a method in the base class is a virtual or pure virtual function (of course the access permission must be public or protected, because from the perspective of C++ design philosophy, private functions will not be virtual, haha), the corresponding function in its subclass The reimplementation of a method is an override. When used, you can determine which method is called through the base class pointer or the specific object pointed by the reference, thereby realizing function polymorphism. For non-virtual type member functions in the base class, if a function with the same name as the function is also declared in its subclass, then the function in the base class (perhaps a series of functions, if the function has If overloaded, haha) will be hidden and can be called through the domain resolution operator. However, according to the design philosophy of C++, non-virtual member functions in the base class do not need to be modified in the subclass. Therefore, if such a hidden situation occurs in the subclass, it means that the base class should be modified. The function in the class is changed to a virtual type, and then it is overridden.
Overload means that in the same scope, multiple functions have the same name, but the number and type of parameters are different (of course, the same number and type, if the order is different, it is OK ), because the mechanism of function overloading is that the signature of a function in C++ is related to its parameters, unlike in C, which is only related to the function name. In short, one of the biggest differences between override and overload is the different scopes and whether the function prototypes are the same, haha.
The overloading (overload) override (override) hiding of the function
The functions of the derived class are exactly the same as the functions of the base class (the function name and parameter list are the same), except that the functions of the base class The function does not have the VIRRUAL keyword. Sometimes the function of the base class will be hidden instead of overridden.
The function of the derived class has the same name as the function of the base class, but the parameter list is different. In this case, regardless of Whether the function declaration of the base class has the VIRRUAL keyword, the functions of the base class will be hidden. Note the difference between this situation and overloading. Overloading occurs in the same class.