How can I “unuse” a namespace?

后端 未结 7 2292
庸人自扰
庸人自扰 2020-11-29 03:01

One of the vagaries of my development system (Codegear C++Builder) is that some of the auto-generated headers insist on having...

using namespace xyzzy
         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 03:47

    Nope. But there's a potential solution: if you enclose your include directive in a namespace of its own, like this...

    namespace codegear {
        #include "codegear_header.h"
    } // namespace codegear
    

    ...then the effects of any using directives within that header are neutralized.

    That might be problematic in some cases. That's why every C++ style guide strongly recommends not putting a "using namespace" directive in a header file.

提交回复
热议问题