Meh*_*dad 1 c++ scope overloading scope-resolution visual-c++
这个函数bar()不能在这里重载的原因是什么?
namespace foo
{
void bar(int) { }
struct baz
{
static void bar()
{
// error C2660: 'foo::baz::bar' : function does not take 1 arguments
bar(5);
}
};
}
Run Code Online (Sandbox Code Playgroud)
它不能超载,因为它们处于不同的范围.第一个bar是foo::bar第二个,而第二个是在foo::baz::bar.
这个名字bar来自外部命名空间是由新的声明隐藏.它必须被显式调用,或者通过using声明显示:
static void bar()
{
using foo::bar;
bar(5);
}
Run Code Online (Sandbox Code Playgroud)