[C ++ foundation] Overload, coverage, polymorphism and function hide

xiaoxiao2021-03-06  111

[C foundation] Overload, coverage, polymorphism and function hide

?

summary:

??????? Overload OverLoad is based on the parameter list of functions to select the function version you want to call, and the polymorphism is based on the actual type of runtime object. If the derived class is implemented to override the virtual Virtual function of the base class, if the classifier does not have the virtual Virtual function of the base class to override Override, the derived class will automatically inherit the base class's virtual Virtual function version, at this time The object of the base class pointer is the base type or the derived type, which will call the base class version of the virtual Virtual function; if the derived class overrides the virtual virtual function of the base class, the actual type of object is selected according to the actual type of object. The virtual Virtual function version to be called, such as the object type of the base class pointer points to the derived type, then the derived virtual Virtual function version is called to achieve a polymorphism.

??????? Use the polymorphism to declare the function in the base class as Virtual, and is to override the virtual virtual function version of the Override base class in the derived class, note that the function prototype and base The class is consistent, that is, the same parameter type; if you add a function version in the derived class, you cannot dynamically call the new function version of the derived class by the base class pointer, this new function version is only an overloaded by the derived class. version. Or the same sentence, the overload is only valid in the current class, whether you are overloaded in the base class, or in the derived class, both are not implicated. If you understand this, in Example 6, Example 9, we will also understand its output results.

?

??????? The overload is static, and the polygon is dynamically coupled. Further explanation, the overload is independent of the type of object that the pointer is actually pointed, and the polymorphism is related to the object type that the pointer is actually pointed. If the base class pointer is called the overload version of the derived class, C is determined that the C sector only believes that the base class pointer can only call the base class's overload version, and overload only the namespace only in the current class. The domain is effective, inheritance will lose heavy-duty characteristics, of course, if the base class pointer is called a virtual Virtual function, then it will also perform the virtual Virtual function version of the base class or the virtual virtual function version of the derived class. To make specific operations, this is determined by the object type actually pointed to by the base class pointer, so that the overload is independent of the object type that the pointer actually points, the polymorphism is related to the object type that is actually pointed to by the pointer. ?

?

??? Finally clarify a little, the virtual Virtual function can also be overloaded, but the overload can only be valid in the current namespace scope (please refer to Example 6 again).

转载请注明原文地址:https://www.9cbs.com/read-124912.html

New Post(0)