Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!tut!tukki.jyu.fi!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.c++ Subject: Re: scope of friend identifiers Message-ID: <1990Aug17.123746.8855@tukki.jyu.fi> Date: 7 Aug 90 06:35:39 GMT References: <5708@darkstar.ucsc.edu> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 57 Note2: Third trial to post! Note1: This is the second posting of an article that apparently disappeared while the news software was out of order here for three days. Sorry if somebody receives it twice. In article <5708@darkstar.ucsc.edu> daniel@terra.ucsc.edu (Daniel Edelson) writes: >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. "Nested classes" in C++ are a pure deception; they are _not_ in the scope of the enclosing class. Thus, the definition of 'in' is actually in an outer scope, and 'frfunc' belongs to the same scope, without the least ambiguity. > [...] The above should answer also most of the rest of the questions in the original posting, or make them irrelevant. >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? My version of the 2.0 Ref. Man. (from sometime in 1989) says in #3.2: "... its name belongs to the enclosing scope; the same is true for a name declared by a friend declaration (#11.4)." There is thus a no contradiction in _that_ version, but if yours is newer, it makes one wonder. Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)