C + + header file with using namespace Std

Source: Internet
Author: User

Recently, we have just started reading the C + + textbook. found that they did not learn seriously, a lot of things pointed to the present only to understand. (Orz, ashamed)

I no longer want to see "using namespace xxx;" In any header file. The

Baidu I found this sentence, a careful look at the reason is because: http://www.ituring.com.cn/article/23606

If you use the using declaration in a header file, you will make this kind of problem even worse, because the naming conflict problem will sooner or later be in a module called very far away from the unknown,

You may need to check the three-layer call to find out why a header file contains another header file that directly uses the using declaration to cause the namespace to be contaminated immediately.

Any file that uses a namespace can cause this type of problem if it uses the contents of the Std namespace.

But a magical #pragma was found in vs once

is a more commonly used C + + pragma, as long as the header file at the very beginning of adding this pragma, you can ensure that the header file is only compiled once. #pragma once is compiler-related, some compiler support, some compilers do not support, please check the compiler API documentation for details, but now most compilers have this pragma. Is it possible to use the using namespace xxx with this sentence ~?!

C + + header file with using namespace Std

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.