C + + name lookup and overloading

Source: Internet
Author: User

The definition of overloaded functions: several functions within the same scope have the same name but different parameter lists, called overloaded functions. Here is an important premise: the same scope;

If the overloaded function is defined in a different scope, then once the compiler finds the desired name in the current scope, the compiler ignores the entity with the same name in the outer scope. The rest of the work is to check if the function call is valid.

Because in this C + +, the lookup of the name occurs before the type check, if a name is found in the current scope, and if there are multiple names, the parameters are matched. If the current scope has only one name, the outer scope is ignored directly for type checking.

The inheritance system of a class also conforms to this situation, so it is best not to reuse the names defined in other base classes in addition to overriding the inherited virtual functions. In this case, the names in the derived class will simply overwrite the members with the same name in the base class.

C + + name lookup and overloading

Related Article

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.