What is the reason why the function bar()
can't be overloaded here?
namespace foo
{
void bar(int) { }
struct baz
{
static void bar()
{
// error C2660: 'foo::baz::bar' : function does not take 1 arguments
bar(5);
}
};
}
It cannot be overloaded because they are at different scopes. The first bar
is at foo::bar
while the second one is at foo::baz::bar
.
The name bar
from the outer namespace is hidden by the new declaration. It has to either be called explicitly, or made visible by a using declaration:
static void bar()
{
using foo::bar;
bar(5);
}