“using namespace” in c++ headers

后端 未结 9 2446
失恋的感觉
失恋的感觉 2020-11-22 01:32

In all our c++ courses, all the teachers always put using namespace std; right after the #includes in their .h files. This seems to me

9条回答
  •  天命终不由人
    2020-11-22 02:14

    Check out the Goddard Space Flight Center coding standards (for C and C++). That turns out to be a bit harder than it used to be - see the updated answers to the SO questions:

    • Should I use #include in headers
    • Self-sufficient headers in C and C++

    The GSFC C++ coding standard says:

    §3.3.7 Each header file shall #include the files it needs to compile, rather than forcing users to #include the needed files. #includes shall be limited to what the header needs; other #includes should be placed in the source file.

    The first of the cross-referenced questions now includes a quote from the GSFC C coding standard, and the rationale, but the substance ends up being the same.

提交回复
热议问题