Topic: Can Nested classes see themselves?


Author: rodb@bridge.com (Rod Burman)
Date: 20 Jul 1994 20:28:05 GMT
Raw View
Consider the code:
  class  Outer {
    class Inner {
       Inner(const Inner&) {}        // copy constructor for demo puposes only
//                 ^(1)
    };
// (2)
  };

Out of a random set of compilers I had handy the C-Front based (SParc and HPUX)
and Borland (4.0) compilers like the above code. The DEC (AXP and VAX/VMS)
complain at the point marked (1) that Inner is not accessable and require
"friend class Inner;" to be inserted at point (2) (or equivalent). I can
see the "logic" of both interpretations:

A) (CFront/Borland) -- Innner must be accessable to itself since all parts of
a class are accessable.
B) (DEC) -- Inner is a private part of Outer and so is only accessable to
Outer and its friends (which Inner isn't).

I personally find proposition (A) more appealing since proposition (B) implies
either:
        i)        You can have a copy constructor for Innner
or      ii)       You must make Inner a friend of Outer which gives it a lot
                  MORE access than neccessary.

What is the official position, DEC quoted the ARM to support their position
and I must admit they seem to be "right" (section 9.7 nested class definitions)
according to the letter of the ARM, but I don't think they have the right
spirit in this case. Are they right? Is the ARM right? Has/will the committee
change this?
    Thanks for your help
                 Rod Burman (rodb@bridge.com)