In article <3e82761b-64af-4004-b0b0-
8d44ca863caa@c33g2000hsd.googlegroups.com>, james.kanze@gmail.com
says...
> On Feb 15, 5:50 pm, Adrian
[ ... ]
> > class foo
> > {
> > public:
> > friend int foo_func();};
>
> > int foo_func();
> > ---------
> > but is this the same:-
> > --------------
> > class foo
> > {
> > public:
> > friend int foo_func();};
>
> > -------------
>
> It depends. Both declare exactly the same function, with
> exactly the same linkage. But in the second case, the scope of
> the declaration is the class, and it will only be found when the
> compiler does a name lookup which includes the class (either
> because it is from a class member function, or due to ADL).
That's how things initially look, but it's not really the case. A friend
is always at namespace scope, regardless of where the declaration is
physically placed. In fact, you can even define the function inside of
the class definition, without it having any effect on scope. For
example, at least as I read things, the following code is well formed:
#include
class X {
friend void f() { std::cout << "found"; }
};
int main() {
f();
return 0;
}
Of course, "well formed" does NOT imply recommended!
--
Later,
Jerry.
The universe is a figment of its own imagination.