From 2702914112067974357
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,ac06fef48c3c04df
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,ac06fef48c3c04df
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1995-01-22 20:02:21 PST
Path: nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!usc!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!news.mit.edu!jgealow
From: jgealow@mtl.mit.edu (Jeffrey C. Gealow)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: friends and local classes
Date: 23 Jan 1995 04:02:21 GMT
Organization: MIT Microsystems Technology Laboratories
Lines: 42
Message-ID: <JGEALOW.95Jan22230221@mtl.mit.edu>
References: <3frgln$deh@senator-bedfellow.MIT.EDU> <3froli$gss@news.panix.com>
	<3fskgs$qsg@engnews2.Eng.Sun.COM>
NNTP-Posting-Host: mtl.mit.edu
In-reply-to: clamage@Eng.Sun.COM's message of 22 Jan 1995 03:47:40 GMT
Xref: nntp.gmd.de comp.lang.c++:87469 comp.std.c++:11217

In article clamage@Eng.Sun.COM (Steve Clamage) 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?

   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.

I understand the rationale for the general rule that friendship is not 
implicit and accept Steve's interpretation of the ARM.  But it seems 
that the rationale, as explained in the ARM, does not apply to the 
situation I presented.  Perhaps I'm missing something?  If not, I think 
the draft standard should be modified so that a local class assumes 
the friendships of the enclosing function.  Note that there is no way 
to use a local class outside the enclosing function and that there is 
no way to explicitly grant friendship to a local class.  If local 
classes are a good idea, why cripple them with rigid access control?  

Jeff


