He probably meant this:
struct foo{
friend void bar(foo* z){} //not static, its friend now
};
foo* z;
bar(z); //fine now
But then technically bar()
is not inside foo
. It is still in the enclosing namespace of foo
.
--
EDIT:
He indeed meant friend
, as he said (emphasis mine):
The best example is a friend function that is defined inside the type
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 bar
is introduced into the scope of the class, but in actuality, the name bar
is introduced into the enclosing namespace of foo
(see §3.3.1/3-4 and §11.3/6).
Here is a better example:
namespace Demo
{
struct foo
{
friend void bar(foo* z){}
};
}
foo *z;
bar(z); //foo (type of z) is inside Demo, so is bar
//(even though bar is defined inside foo!)
bar(NULL); //error - NULL doesn't help ADL.
bar(nullptr); //error - nullptr doesn't help ADL.
bar(static<foo*>(NULL)); //ok - ADL
Note that the name bar
, even though is introduced into the namespace Demo
, is hidden, and thus cannot be used from outside using usual name-lookup:
using namespace Demo; //brings ALL (visible) names from Demo to current scope
bar(NULL); //STILL error - means bar is invisible
Or,
Demo::bar(NULL); //error - not found
Demo::foo::bar(NULL); //error - not found
Hope that helps.