Re: Friend functions and scoping
On Apr 13, 11:25 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
Paul Bibbings <paul.bibbi...@googlemail.com> writes:
"Like a member function, a friend function is explicitly declared
in the declaration of the class of which it is a friend. It is
therefore as much a part of that interface as is a member function."
I am not sure, whether this is always true.
Which part isn't true?
Here, =BBg=AB seems to be declared within the class specifier:
class K { friend void g(); };
void g() {}
int main() { g(); }
But when =BBg=AB is qualified, it does not seem to be declared
anymore:
class K { friend void ::g(); };
void g() {}
int main() { g(); }
"ComeauTest.c", line 1: error: the global scope has no "g"
class K { friend void ::g(); };
(gcc seems to accept this without an error message.)
But in g++, then.
One can remove the error by adding an additional declaration:
void g();
class K { friend void ::g(); };
void g() {}
int main() { g(); }
This has nothing to do with friends. After a scope resolution
operator, qualified name lookup applies, and if the name is not
found, it is an error. The first declaration of a name cannot
use a qualified name.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34