The function friendbelow was not found by the usual search (§7.3.1.2 / 3), but ADL was found (clause 3.3.4 / 4 seconds), so the code compiles and runs normally ( live example ). But a function is fnot declared in any namespace. For example, if you try to replace a call f(x);with any of these calls ::f(x);, A::f(x);or A::X::f(x);, the code will not compile. What namespace contains the declaration of this function? Does the Standard talk about this?
#include <iostream>
namespace A {
class X {
int i;
friend void f(X x) { std::cout << x.i << '\n'; }
public:
X():i(101){}
};
}
int main()
{
A::X x;
f(x);
}
source
share