If a new member variable is added to a derived class that has the same name as a member variable in the base class, the new member variable will obscure the member variable inherited from the base class. Similarly, if a new member function in a derived class has the same name as a member function in the base class, the new member function obscures the member function inherited from the base class.
Connotation of the Satin update
Example 1:
Thunder Member No. 11th share
Music View Members Share
Copy Plain Text New Window
"Before I Go" 2015 High-score action movie
- In this example, you define a base class basic, and then derive the derived class by inheriting the basic class. It is important to note that a member variable x is defined in the basic class, and that the variable is of type int, and the corresponding member function is the SETX and GETX functions. A member variable x is also defined in a derived class, and it is a char pointer type, and the corresponding member function is the SETX and GETX functions. In the main function, the object D1 of the derived class is defined, and we do not have a problem when we call the Setx (char *) function. The setx (int) function inherited from the base class is then called, resulting in a compilation error. Finally, the class name is called to invoke the setx (int) function inherited by the base class, and the compiler passes. In the derived class derived, setx (char *) has the same name as the setx (int) function inherited from the base class, so that the new function setx (char *) of the derived class obscures the setx (int) function inherited from the base class, thus passing D1.setx (50) The call to Setx (int) is unsuccessful, so a compilation error occurs, and the correct invocation method is called by the class name: D1.basic::setx (int).
Free membership from the above example, we can see that the member variable or member function of the masked base class is not inherited, but only is obscured by the member variable and member function of the same name in the derived class, the class name plus the domain resolution operator is required when calling.
C + + hidden files