① Overloading means that different functions use the same function name, but the number or types of parameters of the functions are different. When calling, different functions are distinguished according to their parameters.
② Overwriting (also called rewriting) refers to re-implementing the virtual function in the base class in the derived class (note that it is a virtual function). In other words, the function name and parameters are the same, but the implementation of the function is different.
2. The relationship between classes is different
Coverage is the relationship between subclass and parent class, which is vertical; Overloading is the relationship between methods in the same class, which is a horizontal relationship.
3. Differences in methods
Overrides can only be generated by one method or a pair of methods; Overloading is the relationship between multiple methods.
4. The parameter list needs to be distinguished.
Overwrite requires the same parameter list; Overloading requires a different parameter list.
5. Call method differences
In the superposition relation, the calling method body is determined according to the type of the object; The overloaded relation selects the method body according to the actual parameter table and the formal parameter table when calling.
Extended data
Override of method:
1. In subclasses, methods inherited from base classes can be rewritten as needed.
2. The overridden method and the overridden method must have the same method name, parameter list and return type. (Note: The return value can be a subtype of the return value in the parent class. If a parameter is a subclass, it is not an override but an overload. )
3. Override methods cannot use stricter access rights than overridden methods.
4. An overridden method cannot declare that the type of exception it raises is greater than the scope of the overridden method.
Summary: Rewriting is a change of subclasses to the same method inherited from the parent class. This change needs to follow the format according to the format of the parent class, access rights, throwing exceptions, etc. These are all within the control of the parent method, and the internal concrete implementation can achieve different effects.