问题描述
我的开发系统(Codegear C ++ Builder)的一个变化是,一些自动生成的标题坚持... ...
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
...代码当我最不想要或期望它。
...statements in them, which impact on my code when I least want or expect it.
有一种方法,我可以以某种方式取消/覆盖以前的using语句,以避免这种情况。
Is there a way I can somehow cancel/override a previous "using" statement to avoid this.
也许...
unusing namespace xyzzy;
推荐答案
但是有一个潜在的解决方案:如果你在自己的命名空间中包含你的include指令,像这样...
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
...
在某些情况下可能会出现问题。这就是为什么每个C ++风格指南强烈建议不要在头文件中添加using namespace指令。
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.
这篇关于我如何“不使用”一个命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!