Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Function overloading problem (global versus member)

15 views
Skip to first unread message

JiiPee

unread,
Dec 31, 2017, 4:34:12 PM12/31/17
to
I dont understand why that foo(p); does not find the correct foo-version
automatically even though its obvious it should call the global
foo(const Player& player);. Can anybody please explain why its trying to
call the foo(const std::string& name, int a) version (and causing a
compilation error-) even though there is perfect match with the global
version?

Just would like to know the theoretical reason for this. (I know
::foo(p);  solves it, but is that the only solutions? I would rather not
put those :: ).

thanks


class Player
{
};

void foo(const Player& player);

class A
{
public:
    std::string name_;
    void foo(const std::string& name, int a)
    {
        Player p;
        foo(p);
    }
};

void foo(const Player& player)
{

}

int  main() {
    A a;
    a.foo("sdf", 9);
    return 0;
}

JiiPee

unread,
Dec 31, 2017, 6:15:13 PM12/31/17
to
On 31/12/2017 22:46, Stefan Ram wrote:
> JiiPee <n...@notvalid.com> writes:
>> void
> ...
>>     void
> The second declaration appears in a scope that is nested in
> the scope of the first declaration. Therefore, the second
> declaration /hides/ the outer declaration of the same name
> [basic.scope.hiding], and hidden names do not take part in
> name resolution.
>
ok, thanks, I thought its something like this.

0 new messages