Compile process using the C + + compiler

Source: Internet
Author: User

The type lookup process in C + + is relatively simple, basically a name lookup, which is no longer described here. You can learn C + + programming-basic knowledge tutorial.

For a function (or member function) called in a. cpp file, the compiler mainly does the following three things:
1, name search. First name lookup is performed in the visible name entity in the compilation unit where it is located. (1) The class member function takes precedence (the class that the object resides in, and the base class). Stop the lookup once it is found. (2) If not, do a further search in the appropriate namespace; (3) If not, it will be looked up according to the namespace in which the function parameter resides (keoning lookup).
2, overload resolution. The overload resolution is based on the name found, and the corresponding function is selected according to the principle of the parameter matching.
3, accessibility check. Used to determine whether the selected function can be called.
Description
1) According to the first article, it is obvious that if a type wants to work with a non-member function, they should be placed in the same namespace. For example, a generic type of overloaded operators and parameter types are placed in the same header file/or under the same namespace.
2) The function special template does not participate in overload resolution, so if you want to use a function of the special, the best way is to overload the function, in the implementation of the use of this special to work.
3) Overload resolution occurs before the accessibility check. Therefore, if the private function unfortunately participates in the overload and is selected, there will eventually be an unreachable compilation hint. This often implies ambiguity, and the design itself is unreasonable. In other words, private parameters are not "private" when the name is searched and overloaded.
The rules in the article are very important, and after understanding, many C + + compiler problems will be solved naturally. There will be further articles on how to determine the visible names in each C + + compilation unit (CPP file), which are related to the name lookup, the keoning lookup, the overloading (overload), and the implementation of the virtual function (override). To learn more programming language Tutorials Please login e mentor Web.

Compile process using the C + + compiler

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.