将`using`指令限制到当前文件 [英] Restricting `using` directives to the current file

查看:142
本文介绍了将`using`指令限制到当前文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个愚蠢的问题,很抱歉,但是有任何方式限制使用指令到当前文件,以便它们不会传播到 #include 此文件?

Sorry for this silly question, but is there any way to restrict using directives to the current file so that they don't propagate to the files that #include this file?

推荐答案

可能包含代码以包含在自己的命名空间可以实现

的行为,因为命名空间有作用域。

Perhaps wrapping the code to be included inside its own namespace could achieve the behavior
you want, since name spaces have scope affect.

// FILENAME is the file to be included
namespace FILENAME_NS {
   using namespace std;
   namespace INNER_NS {
      [wrapped code]
   }
}
using namespace FILENAME_NS::INNER_NS;

和其他档案

#include <FILENAME>
// std namespace is not visible, only INNER_NS definitions and declarations
...

这篇关于将`using`指令限制到当前文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆