C + + hidden files

Source: Internet
Author: User

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
  1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.