This is follow up question from Does argument dependent lookup only search namespaces or classes too? , In which @David Rodríguez said “ADL will look in the enclosing namespace of the type, and also inside the type itself” . I may have got him wrong what he tried to say but I was trying this example:
struct foo{
static void bar(foo* z){}
};
int main(){
foo* z;
bar(z);
}
It doesn’t compiles, producing the error ” ‘bar’ was not declared in this scope ” . Is it the case that ADL doesn’t considers the static member function?. I mean in the example associated class is foo so wouldn’t ADL look inside the class? . Can anyone please simplify the rules here?
He probably meant this:
But then technically
bar()is not insidefoo. It is still in the enclosing namespace offoo.—
EDIT:
He indeed meant
friend, as he said (emphasis mine):And his example illustrates further. Probably you need to read “defined inside”, rather than only “inside”.
The word “defined” is all that makes the difference, because it looks like the function’s name
baris introduced into the scope of the class, but in actuality, the namebaris introduced into the enclosing namespace offoo(see §3.3.1/3-4 and §11.3/6).Here is a better example:
Note that the name
bar, even though is introduced into the namespaceDemo, is hidden, and thus cannot be used from outside using usual name-lookup:Or,
Hope that helps.