Topic: Access control and nested types question


Author: sdouglass@armltd.co.uk (scott douglass)
Date: 24 Mar 1995 11:16:25 GMT
Raw View
Hello,

Can one private nested type use another type that is also private member
of the same class:

class T {
   enum N1 { a, b, c };
   typedef N1 (*N2)(N1);
};

I believe the working paper does not address this.

(9.2) "Members of a class are data members, member functions, nested
types, and member constants. ... Nested types are classes and enumerations
defined in the class, and arbitrary types declared as members by use of a
typedef declaration."

So N1 and N2 are members of T.

(11) "A member of a class can be
    -- private; that is, its name can be used only by member functions and
friends of the class in which it is declared.

     -- protected; that is its name can be used only by member functions
and friends of the class in which it is declared and by member functions
and friends of classes derived from this class.

    -- public; that is its name can be use by any function."

So N1 and N2 are private members.  The problem is that the phrase used in
(11) is "member functions and friends".

N2 is a member but not a member function.  Can it "use" N1?

What about the following? Given:

      struct S { typedef int INT;  enum { a }; static INT i; };

'INT' and 'a' are public members. I believe the following uses are are
intended to be legal but none of the uses is by "any function":

      S::INT i = a;
      typedef S::INT Size;
      enum { b = S::a + 1; };

If all of these are intended to be legal I would be so bold as to suggest
that the beginning of (11) be worded something like:

(11) "A member of a class can be
    -- private; that is, its name can be used only by declarations
(including definitions) of members and friends of the class in which it is
declared (subject to scoping rules).

     -- protected; that is its name can be used only by declarations
(including definitions) of members and friends of the class in which it is
declared and by member functions and friends of classes derived from this
class (subject to scoping rules).

    -- public; that is its name can be use by any declaration (subject to
scoping rules)."

What do you think?  Is there some other part of the standard that already
makes my examples legal?  Are they supposed to be illegal?

(9.8) which specifically says nested classes have no specical access to
the members of the encolsing class, also uses the phrase "member functions
and friends" where "declarations (including definitions) of members and
friends" might be better.

Thanks,
       --scott




Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: Mon, 27 Mar 1995 20:01:46 GMT
Raw View
In article <sdouglass-2403951115040001@193.131.176.202>,
scott douglass <sdouglass@armltd.co.uk> wrote:
>Hello,
>
>Can one private nested type use another type that is also private member
>of the same class:
>

 No. But it has been repeatedly suggested it should be able
to. I'll double check, but I suspect a proposal to the committee
to allow a nested type access to members of the containing
type might well be accepted. (If it hasn't been already).

 If this doesn't make it into the CD, bring it up
during public review.

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189