From: jbn@lulea.trab.se (Johan Bengtsson)
Newsgroups: comp.lang.c++
Subject: Re: Inherited nested classes?
Date: 28 Aug 92 11:57:12 GMT
Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
X-Newsreader: Tin 1.1 PL4

girod@tele.nokia.fi (Marc Girod) writes:
: In article <4862@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
: >    jane@mullian.ee.mu.OZ.AU (jane lynette cosham) writes:
: >    : 
: >    : The problem is that MSC 7.0 inherits nested classes and BC 3.0
: >    : doesn't.  MSC also takes note of access modifiers for nested classes.
: > [...]
: > 
: >    Good!  MSC conforms to the base document for the C++ standard,
: >    the Annotated Reference Manual (it's described on page 48).
: 
: Unfortunately, we don't read the same things from the same place... To
: me, ARM p 48 doesn't deal with nested classes (or so marginally that
: it is not relevant here!

On reading p48 again, I must admit that you are right.  p48 does not
say what I thought it did (but it should).

: It deals with "names", defined at the bottom
: of p 47 as "a form of primary-expression that can appear after. and
: ->"

A strange definition of "name" don't you think?  Should be "member-name",
if types are really not "names".  Fine.

: 
: To me, the section 9.7 on "Nested Class Declarations" doesn't either
: bring any light onto the issue, apart for the not-so-clear: "The name
: of a nested class is local to its enclosing class", the important word
: being "local". We are thus back to the section 3.2 on "Scopes", p 15,
: which states about Local scope: "A name declared in a block is local
: to that block and can be used only in it and..."; and about Class
: scope: "The name of a class member is local to its class and...". A
: nested class is not a member, so:
: 
: >    : Under BC neither class exists for B, and it is possible to declare a
: >    : variable of type A::nested_a2 anywhere.
: >    : 
: >    : It is my understanding that Borland's implementation is the norm.
: 
: ..was the correct interpretation.

... contradicting ARM p216 (scope rule summary):

"The scope rules for C++ [...] apply uniformly for all names (including
 typedef-names and class names), wherever the grammar allows such names
 in the context discussed by a particular rule."

Does sound reasonable, no?  I should have tested this with my compilers
first though.  Your view seems to win 2-1 (Sun C++ 2.1 & g++ 1.40.3 vs
ObjectStore C++ 2.1).

The differences between "member" and "nested" seem so unnecessary to me.
Why, oh why?

: > jane@mullian.ee.mu.OZ.AU (jane lynette cosham) writes:
: > [...] however it causes hassles if the same name cannot be used in
: > more than one level of the class structure.

But it can (should).  A nested type name used in a derived class hides
the same nested type in a base class, just like all other names.
In that case, you need to qualify, Base::NestedType, if that is
what you mean.  If this is really a good idea is another issue.

-- 
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| jbn@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490              |
--------------------------------------------------------------------------
Newsgroups: comp.lang.c++