C ++ hide

Source: Internet
Author: User

C ++ hide

The overload of C ++ is that multiple functions in a class have the same name and meet the requirements of the overload. For example, the parameters are different.

The rewriting of C ++ must be that the parent class function has the virtual keyword. Subclasses can be rewritten.

If the function of the parent class does not have the virtual keyword. When a subclass is overwritten, It is not overwritten. It is hidden.

If the parent class has a virtual function.

To rewrite a subclass, the function name and parameters must be the same. If the parameters are not the same, it is not rewritten. It is hidden.

Hiding means hiding the actual function or the actual subclass type. Only interfaces defined by the outermost layer are exposed.

Hiding a function may cause an error for a friend who wants to use polymorphism. A parent class Pointer Points to a subclass object. After the hidden implementation, the function you call is not a subclass. It is the parent class.

This is because there are many inheritance in C ++. So without hiding, you cannot figure out which parent class function to call.

This problem does not exist in Java. Because it is a single inheritance. Subclass will only override the method of the parent class and will not hide it.

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.