N
neverhoodboy
We know that argument-dependent-lookup can be used to find namespace-
scope friend function defined in some class which is otherwise not
visible using an ordinary lookup. My question is, can the argument be
of some class in the same namespace other the enclosing class of the
friend function? Please see the following code snippet:
namespace NNN
{
class BBB {};
class AAA
{
public:
friend void func() {}
friend void funca(AAA&) {}
friend void funcb(BBB&) {}
};
}
int main()
{
NNN::AAA a;
NNN::BBB b;
NNN::func(); // this will fail to compile for sure
funca(a); // this will compile with no problem because of ADL
funcb(b); // shall this compile? various compilers at my hand
give different results, so I'm asking for help to understand the exact
requirement of the C++ standards.
}
scope friend function defined in some class which is otherwise not
visible using an ordinary lookup. My question is, can the argument be
of some class in the same namespace other the enclosing class of the
friend function? Please see the following code snippet:
namespace NNN
{
class BBB {};
class AAA
{
public:
friend void func() {}
friend void funca(AAA&) {}
friend void funcb(BBB&) {}
};
}
int main()
{
NNN::AAA a;
NNN::BBB b;
NNN::func(); // this will fail to compile for sure
funca(a); // this will compile with no problem because of ADL
funcb(b); // shall this compile? various compilers at my hand
give different results, so I'm asking for help to understand the exact
requirement of the C++ standards.
}