From owner-freebsd-hackers Thu Oct 17 21:54:13 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id VAA24337 for hackers-outgoing; Thu, 17 Oct 1996 21:54:13 -0700 (PDT) Received: from rocky.mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id VAA24330 for ; Thu, 17 Oct 1996 21:54:10 -0700 (PDT) Received: (from nate@localhost) by rocky.mt.sri.com (8.7.5/8.7.3) id WAA22620; Thu, 17 Oct 1996 22:54:07 -0600 (MDT) Date: Thu, 17 Oct 1996 22:54:07 -0600 (MDT) Message-Id: <199610180454.WAA22620@rocky.mt.sri.com> From: Nate Williams To: hackers@freebsd.org Cc: Nate Williams , mrs@sygnus.com Subject: Re: C++ question In-Reply-To: <3266CD1E.41C67EA6@fsl.noaa.gov> References: <199610172119.PAA20617@rocky.mt.sri.com> <3266AE63.41C67EA6@fsl.noaa.gov> <199610172209.QAA21050@rocky.mt.sri.com> <3266CD1E.41C67EA6@fsl.noaa.gov> Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk class foo { private: struct A { int myint; } struct B { A *ptr; // Disallowed in the C++ standard } }; > [ Sun's ] compiler notes explicitly (well, not so explicitly) say > that newer C++ standards don't allow this. Mike Stump (who is the C++ standards guru for Cygnus) responded with the following: Sun's compiler is correct. To access it, you must say it is a friend: 11.8 Nested classes [class.access.nest] 1 The members of a nested class have no special access to members of an enclosing class, nor to classes or functions that have granted friend- ship to an enclosing class; the usual access rules (_class.access_) shall be obeyed. The members of an enclosing class have no special access to members of a nested class; the usual access rules (_class.access_) shall be obeyed. [Example: class E { int x; class B { }; class I { B b; // error: E::B is private int y; void f(E* p, int i) { p->x = i; // error: E::x is private } }; int g(I* p) { return p->y; // error: I::y is private } }; --end example] So, in order to be fully conforming the code could be written as follows: class foo { private: struct A { int myint; } // The C++ standard requires the friend stuff struct B; friend struct B; struct B { A *ptr; // Disallowed in the C++ standard } }; Thanks to all, especially Mike who provided both the validation of the Sun compiler and the solution. Nate