为什么我必须为嵌套匿名名称空间中的函数指定外部名称空间
Why do I have to specify the outer namespace for a function in a nested anonymous namespace?
给定一个命名空间a。内部是一个带有函数f和类X的匿名命名空间,也带有函数f:当从a::X::f调用匿名f时,为什么必须指定外部命名空间a::作为限定符?
作为一个最小的例子:
#include <iostream>
using namespace std;
namespace A {
namespace {
int f( int i ) { return i; }
}
class X {
public:
static int f() { A::f( 10 ); }
};
}
int main()
{
cout << A::X::f() << endl;
return 0;
}
因为在X::f
的范围内,非限定名称f
指的是X::f
,而不是任何其他f
。在作用域内声明的名称将隐藏外部作用域中具有相同名称的任何内容。
相关文章:
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 在命名空间中定义函数还是限定函数
- CUDA内核和数学函数的显式命名空间
- 在命名空间中使用全局命名空间中的函数
- 是否可以将函数导入命名空间,但不能导出它?
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- 是否有 Windows 用户空间函数来枚举连接的网络共享?
- 使用类指针重载C++命名空间函数模板专用化替代方法?
- 在头文件中添加命名空间函数
- 命名空间函数的多重定义
- 在多个 cpp 文件中重用未命名的命名空间函数
- Ubuntu,如何找到内核工作繁重的程序热点?似乎kernel.kallsyms上的函数没有标记为用户空间函数的子级
- 如何正确声明命名空间函数
- 使用 libclang 解析命名空间函数
- C++命名空间函数
- 内联命名空间函数时出错
- 递归std::functional与递归匿名命名空间函数.使用哪一个
- c++ Koenig(参数依赖)查找:如果不同名称空间中的两个名称空间函数具有相同的参数类型该怎么办?
- 名称空间函数定义中的这种所谓查找是什么
- 如何在命名空间函数中使用pragma weak