From -6046189302089563969
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ac06fef48c3c04df
X-Google-Attributes: gidf78e5,public
X-Google-Thread: 109fba,ac06fef48c3c04df
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 1995-01-21 19:47:40 PST
Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!gw1.att.com!fnnews.fnal.gov!uwm.edu!spool.mu.edu!olivea!koriel!male.EBay.Sun.COM!engnews2.Eng.Sun.COM!clamage
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: friends and local classes
Date: 22 Jan 1995 03:47:40 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Lines: 43
Message-ID: <3fskgs$qsg@engnews2.Eng.Sun.COM>
References: <3frgln$deh@senator-bedfellow.MIT.EDU> <3froli$gss@news.panix.com>
NNTP-Posting-Host: taumet.eng.sun.com
X-Newsreader: NN version 6.5.0 #21 (NOV)
Xref: nntp.gmd.de comp.lang.c++:87408 comp.std.c++:11203

Viktor Yurkovsky <n4mation@panix.com> writes:

>jgealow@mtl.mit.edu (Jeffrey C. Gealow) wrote:
>>
>> Should a local class assume the friendships of the enclosing function?  
>> For example, consider the following:
>> 
>> class X {
>>   int i;
>>   friend int f(X);
>> };
>> 
>> int f(X o)
>> {
>>   struct local {
>>     static int l(X o) { return o.i; }  // error?
>>   };
>>   return local::l(o);
>> }
>> 
>> Should struct local, declared within the definition of f(X), act 
>> as a friend of class X?
>
>Seems to me that friend applies to the entire function, and anything
>inside that function should have access.

No.

No function is a friend of a class unless that class so declares
that function. Since local::l is not declared to be a friend of X,
it isn't a friend.  (It cannot be so declared because it isn't visible.)

Friendship is not inherited, isn't implicit, and cannot be asserted.

See ARM 11.4.

N.B.: A shorthand notation allows all the member functions of a
class to be simultaneously declared to be friends of another
class. That notation is not used here (and can't be used, because
the class "local" isn't visible).

--
Steve Clamage, stephen.clamage@eng.sun.com


