Question

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); 
        }
    };
}
Was it helpful?

Solution

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); 
}

OTHER TIPS

Is this what you're trying to do?

namespace foo
{
    void bar(int) { }

    struct baz
    {
        static void bar()
        {
            // error C2660: 'foo::baz::bar' : function does not take 1 arguments
            foo::bar(5); // <-- changed
        }
    };
}

EDIT: That's also obviously not going to be overloading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top