Compiler Principle:
The compiler uses different internal names F () to distinguish two functions:
Example:
Class
{
Void F (float, INT );
}
The compiler converts it to the format of _ x_f_float_int;
* Features overloaded by member functions
1: the same range (in the same class );
2: The function name is the same;
3: different parameters (number of parameters, parameter class );
4: Virtual keywords are optional.
5: The default real parameters cannot be defined through access permissions, return types, and thrown exceptions are overloaded;
6: Polymorphism during overload Compilation
7: Any program has only one main function instance, and the main function cannot be reloaded;
8: If a function has a default real parameter, the real parameter can be less required when calling the function than the real parameter;
(To find the most perfect match: The principle is that the closer the real parameter and the shape, the better the match,
1: exact match 2: improve by class shape 3: pass standard conversion 4: pass class shape conversion)
9: whether the referenced parameter of a function points to the const object or to a non-const object can be overloaded;
10: when multiple virtual functions are overloaded in the base class and the base class virtual functions are redefined in the subclass, the compiler does not allow us to change the returned values of the redefined functions;
(This is acceptable if it is not a virtual function );
(Note: The overload cannot be implemented based on whether the pointer itself is const)
* Override refers to a function of the derived class that overwrites the base class function. The feature is
1: different scopes (located in the derived class and the base class respectively );
2: the flag of the override method must match the flag of the overwritten method to achieve the overwriting effect (the function name and parameter are the same );
3: The returned value of the overwritten method must be the same as that of the overwritten method;
4: The exception thrown by the overwriting method must be the same as the exception thrown by the overwriting method, or its subclass;
5: basic functions must have virtual keywords;
6: The method to be overwritten cannot be private. Otherwise, a new method is defined in its subclass and not overwritten;
7: Polymorphism during override operation
* "Hide" means that the function of the derived class shields the base class functions with the same name as it. 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. In this case, functions of the base class will be hidden regardless of whether there is any virtual keyword (Be sure not to confuse them with 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. At this time, the base class functions are hidden (Be sure not to confuse with overwrite)
3: redefines an overload function in the base class at any time. All other versions of the new class are automatically hidden;