First, we will introduce the first three concepts. These three concepts are consistent. Different books have different names,
But they are essentially the same.
All reflect an important feature of the object-oriented programming language.
Key words: (dynamic binding, polymorphism, function coverage), base class, derived class, base class pointer (reference), virtual function
Implementation Method: In C ++, dynamic binding occurs when a virtual function is called through a reference (or pointer) of a base class. Reference (or pointer) can refer
A base-class object can also point to a derived-class object, which is the key to dynamic binding. When a virtual function called by reference (or pointer) is running
OK. The called function is defined by the actual type of the object referenced (or pointer.
Differences from function overloading: Many beginners, even some of whom have been learning for a while, will confuse them. First, function Overloading is in our learning class.
You have learned before the type. For classes, function overloading only defines the same function name in the same class scope, but the function of different parameter types.
Number. It has nothing to do with the inheritance level of the class, and is there any virtual OK.
Function coverage (polymorphism) is an important concept proposed in the hierarchy of class inheritance. The base class must have a letter specified by virtual to overwrite
Number.
There is another concept that troubles beginners, namely function hiding.
"Hide" refersThe function of the derived class shields the base class functions with the same name., The two conditions 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, the function of the base class will
Hidden (Be sure not to confuse with overload, and overload is in the same class ).
(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
Class functions are hidden (do not confuse with overwrite. The base class functions to be overwritten must be virtual ).