我的代码包含一些大型开源项目的标头。其中一个是C,另一个是C ++。不幸的是,C标头声明的结构与map
和list
之类的C ++标准模板库(std::)类具有相同的名称。我在这些上收到“模棱两可的符号”错误。事实证明,C ++项目在某些头文件中有using namespace std;
。如果可以避免,我不想分叉这些软件包并对其进行修改,因为这将是一项艰巨的任务。
是否可以代替“关闭”我代码中的using namespace std
,以便它不会尝试将list
或map
解析为可能属于该名称空间?请参见下面的代码示例和所需的not_using
指令。我知道not_using
不存在。我正在寻找一种实现这种效果的方法。
using namespace std;
map<string, string> mapOk; // compiles but conflicts with C symbol
not_using namespace std; // I need something like this because...
std::map<std::string, std::string> mapOk2; // I want to force the use of std:: to resolve
map<string, string> badMap; // Causes compile error