This is the mail archive of the
mailing list for the GCC project.
Re: Namespace Lookup
> Because of a rule called Koenig lookup [basic.lookup.koenig]. For
> short, it states that a function argument of a particular class type
> causes functions in the scope of that class to be considered for
> overload resolution.
Thanks for the pointer. Let me see whether I understand this correcly.
There is a set of associated namespaces and classes for the call, and
lookup searches all of them (unless it first finds a member). So
void f(struct B::X);
friend void A::f(X);
void f(int, X &);
f(4,x); //calls A::B::f(int, A::B::X&);
f(x); //calls A::f(A::B::X);
is correct. What about
bar(quux); //error: call to non-function Foo::bar
It seems that Koenig lookup considers Foo, and finds its member bar.
It then sees that it is not a function, so the call is invalid. Right?
Now, what about
static int bar(Foo&);
void foobar(Foo quux)
This should find both ::bar, and Foo::bar, and select the latter. Right?