Differences between function coverage and hidden overloading in C ++

Source: Internet
Author: User

In the inheritance section, C ++ involves covering hidden overloading of functions. How can we differentiate them?

First, the function coverage condition: <1> the base class function must be a virtual function.

<2> the two functions that are overwritten must be located in the derived class and the base class respectively.

<3> the function name and parameter list are identical.

Second, function hiding mainly involves the following two situations:

<1> the functions of the derived class and the base class functions are identical (the function names and parameter lists are the same), but the base class functions do not use the virtual keyword. In this case, the function of the base class will be hidden rather than overwritten.

<2> a function of a derived class has the same name as a function of a base class, but the parameter list is different. In this case, no matter whether the function declaration of the base class has a virtual keyword, functions of the base class are hidden. Pay attention to the difference between this situation and function overload. The overload occurs in the same class.

Finally, the function overload condition occurs in the same class, with the same function name and different parameter class tables or types.

 

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.