Consider the following:
namespace N { struct A { }; struct B { B() { } B(A const&) { } friend void f(B const& ) { } }; } int main() { f(N::B{});
In the first case, the case succeeds - we consider the associated namespaces N::B and find N::f(B const&) . Fine.
The second case fails. What for? According to [namespace.memdef] :
If a friend declaration in a non-local class first declares a class, function, template, or function template, it is a member of the innermost enclosing namespace. [...] If the template of the function or function of a friend, its name can be found by a name that considers functions from namespaces and classes associated with the types of function arguments (3.4.2).
The associated namespace N::A is N , of which f is a member, so why is it not found by searching?
c ++ language-lawyer argument-dependent-lookup friend-function
Barry
source share