From -480044034989906760
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-02-09 05:00:19 PST
Path: swrinde!howland.reston.ans.net!news.sprintlink.net!uunet!easix!gtnduss1.du.gtn.com!news.uni-stuttgart.de!uni-regensburg.de!fauern!gs.dfn.de!tubsibr!ti953017
From: ti953017@rzcipa01.rz.tu-bs.de (Andreas Rossberg)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: friends and local classes
Date: 8 Feb 1995 11:01:11 GMT
Organization: TU Braunschweig, FRG
Lines: 75
Distribution: world
Message-ID: <3ha89n$6pb@ra.ibr.cs.tu-bs.de>
References: <FENSTER.95Jan24182929@ground.cs.columbia.edu> <3gpb3n$nh4@booz.bah.com> <D3DF84.o8@cwi.nl> <3gt6ge$q3m@hpsystem1.informatik.tu-muenchen.de>
NNTP-Posting-Host: rzcipa03.rz.tu-bs.de
Xref: swrinde comp.lang.c++:112862 comp.std.c++:12969

In article <3gt6ge$q3m@hpsystem1.informatik.tu-muenchen.de>,
Ulf Schuenemann <schuenem@Informatik.TU-Muenchen.DE> wrote:
>
>class C {
>	// we will look at usage of these 3 private members of C
>	class N0 {
>		static int	classvar;
>		int		instvar;
>	public:			N0	() {}
>	};
>
> [...]
>
>	struct N1 {
>		// interestingly, gcc allows the usage of memberclass N0
>		// insinde N1 although it's private to C (*) (**)

    Yes, actually _all_ of the below code is illegal.

>		N0		* n0p;
>		static void	f(N0 & n0)
>		{	N0	my_n0;	// OK: public member of C::N0
>			N0::classvar++;	// ERROR: private member of C::N0
>			n0.classvar++;	// ERROR: private member of C::N0
>			n0.instvar++;	// ERROR: private member of C::N0
>		}
>		// currently: N1 may not use membervariables of C::
>		// because they are private (*)
>		static void	g(C&c)
>		{	C::classvar++;	// ERROR (*)
>			c.classvar++;	// ERROR (*)
>			c.instvar++;	// ERROR (*)
>		}
>	};
>	...
>};
>
>(*) The idea is to clearly allow all members (including memberclasses)
>of a class the usage of all other (including private) members of that class.
>


Please note that `access' is not something involving just functions.
Access rules apply uniformingly to all _names_ -- not to objects. And any
declaration, for example, can access names, not just the code of functions.

So, when talking about access granted to a nested class, this applies not
only to member functions but to the class as a whole.

Another example I already pointed out in my original posting:

	class A
	{
		typedef int T;
		enum { e = 10 };

		class B
		{
			T t;		// currently illegal
			int a[e];	// currently illegal
		};
	};

No functions or objects involved here.

Also note that this is not just an academical discussion. In my experience,
cases like this appear rather frequently if you make serious use of the
structured concept of nested classes.


	- Andreas Rossberg


PS: To make the current rules consequent, wouldn't it be necessary to
    disallow B to access its own name since it's private to A?  :-)


