c++ - 在命名空间中时如何为变量指定根命名空间

标签 c++

当我这样做时它会起作用:

namespace UnitTesting {class UnitTest_1;}

namespace NLa
{
    class Search
    {
       friend class UnitTesting::UnitTest_1;
    }
}

但是如果 class UnitTest_1 不在命名空间中怎么办?

最佳答案

使用::前缀访问全局/未命名的命名空间

friend class ::UnitTest_1;

你的原始样本可以很容易地写成

friend class ::UnitTesting::UnitTest_1;

关于c++ - 在命名空间中时如何为变量指定根命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9315448/

相关文章:

c++ - 带有引用元组的结构化绑定(bind)引用

c++ - 使一个exe低优先级

c++ - 为什么通过基指针删除 [] 派生对象数组是未定义的行为?

c++ - 将 std::map 转换为 Rcpp::List?

c++ - 在线C++编译器: output binary files for me?

c++ - 类、函数的前向声明

c++ - DirectX 9 地形生成 C++

c++ - 向其他进程发送消息

c++ - 如何将多维映射从 c++ 转换为 perl 中的哈希

c++ - Windows 7 异常代码 : 0xc0000409