home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!ut-emx!jamshid
- From: jamshid@ut-emx.uucp (Jamshid Afshar)
- Newsgroups: comp.lang.c++
- Subject: Re: static data members of private types impossible?
- Summary: ARM says illegal, committee's debating it. I think it should be legal
- Message-ID: <84172@ut-emx.uucp>
- Date: 22 Nov 92 23:06:00 GMT
- References: <1992Nov12.151014.10610@debbie> <5207@holden.lulea.trab.se>
- Reply-To: jamshid@emx.utexas.edu
- Organization: The University of Texas at Austin; Austin, Texas
- Lines: 64
-
- In article <5207@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
- >johnh@tt.com (John Hasselkus) writes:
- >: class A {
- >: enum FOO { FOO_1, FOO_2 };
- >: static FOO foo;
- >: };
- >:
- >: A::FOO A:foo; // <- Compiler won't let you use private types out here
-
- While I would not have interpreted the ARM this way, I have been told
- that its intentions are that the above is illegal. I've also been
- told this matter is being discussed by ANSI and that and they are
- leaning towards relaxing the rules to allow the above code. Otherwise
- nested types would have to be made public in many situations where the
- class writer really doesn't want them to be.
-
- >To support this, the compiler would need to parse the entire declaration,
- >before deciding if in fact the type name is accessible. My guess is that
- >compilers rather not do that.
- >To prove my point, the following declaration should definitely be illegal:
- >A::Foo A::foo, anotherVariable;
-
- The compiler could simply give an error that A::Foo is not accessible
- at file scope unless the object being declared has access. I think
- this situation is very analogous to that of resolving overloaded
- functions, some of which might not be accessible. From ARM 11.3c
-
- As mention in $11, C++ provides access control, not visibility
- control; that is, the object, function or whatever referred to
- in an expression is determined WITHOUT REGARD TO ACCESS
- SPECIFICATION, then type checking is done, and only if no error
- was found is access control applied.
- [emphasis mine]
-
- Making non-public types inaccessible at file scope even when declaring
- a member would also mean that member functions could only return
- non-public types:
-
- class A {
- enum FOO { FOO_1, FOO_2 };
- static FOO foo(); // impossible to define this
- //...
- };
-
- Or, even weirder, it would mean they could only be defined inside the
- class. Granted, this type of restriction does have precedence with
- local classes.
-
- Btw, there's some code in ARM 9.7 p187 that uses a private type in
- file scope and I think contradicts the ARM intentions (unless typedef
- declarations don't count):
-
- class enclose {
- class inner { ... };
- };
- typedef enclose::inner ei;
- //...
-
- Was this changed in the ARM reprinting (May92)? Anyway, I hope ANSI
- does decide to allow the use of non-public types in file scope when
- declaring members and I hope compiler writers are quick to respond.
-
- Jamshid Afshar
- jamshid@emx.utexas.edu
-