Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!decwrl!apple!agate!darkstar!terra.ucsc.edu!daniel From: daniel@terra.ucsc.edu (Daniel Edelson) Newsgroups: comp.lang.c++ Subject: scope of friend identifiers Message-ID: <5708@darkstar.ucsc.edu> Date: 3 Aug 90 17:45:52 GMT Sender: usenet@darkstar.ucsc.edu Reply-To: daniel@terra.ucsc.edu (Daniel Edelson) Organization: University of California, Santa Cruz Lines: 67 The rules governing names introduced in friend declarations appear somewhat ambiguous according to [E&S 90], section 11.4. It says ``If a class or function mentioned as a friend has not been declared its name is entered in the same scope as the name of the class containing the declaration.'' Does this imply that a friend declaration in a nested class declares a member function of the enclosing class? E.g., struct out { struct in { friend void frfunc(); }; }; According to the rule, the name frfunc is scoped to out. Therefore, must I use out::frfunc to define the function? void out::frfunc() { /* ? */ } Have I now declared a member function of out without using the standard syntax? Or alternatively, is frfunc NOT a member of out, but rather a function whose name is simply in the scope of out, with scope and membership being somewhat orthogonal. Or, on the contrary, am I interpreting the rule incorrectly. Does it simple mean that the friend function is in the scope of out in the following respect? struct out { static int outstat; struct in { friend void frfunc(); }; }; void frfunc() { int i = outstat; /* Am I in the scope of out? */ } Or both? Similar semantic ambiguities apply to class names first appearing in friend declarations. struct out { struct in { friend struct frstruct; }; }; Is struct frstruct a nested type of struct out? Then again, in section 3.2 the discussion of class scope says that ``A name first declared by a friend declaration belongs to the global scope;'' which, if true, contradicts the 11.4 statement and renders this discussion moot. Is there a diffinitive answer as to which section is correct? Daniel Edelson daniel@cis.ucsc.edu