Solve the problem of class name and variable name conflict in ambiguous symbol namespace

Source: Internet
Author: User

Recently, a complex project has been integrated into an existing project. Compile-time found that some variable names conflict, the hint is xxxx ambiguous symbol, and in the compilation output, the specified two files in the specific variable name or the same class name. This compilation error occurs because two header files are loaded in the project, the two header files contain the same class name or variable name, and the method to resolve and avoid such errors is as follows:

  1. The code base is included in a namespace as much as possible. When we write a large program, some variables may have the same name as other projects, so it is necessary to add namespaces, in addition, the names of the class name variables named in their own code base try to start with the code base , which greatly reduces the likelihood of conflicts with other code library naming;
  2. use namespace xxx is forbidden in the header file. This is critical, the header file uses the namespace, then the file loaded with the header file, loaded the namespace, causing the header file pollution, the correct way is to add the header file, but before the specific class name using the domain identifier, such as std::string;
  3. There is also a lazy way to specify their domain identifiers directly in the conflict, but assuming that there are a lot of conflicts, then this method is cumbersome, it is recommended to use 1 and 2 to solve the problem from the root.

  

Solve the problem of class name and variable name conflict in ambiguous symbol namespace

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.