sorc@edsr.eds.com (Sorc Kirishi) (06/22/91)
I want to be able to do a typedef within the private section of a class, and have the scope of that typedef be that class only. Apparently this is impossible in C++. Am I correct in this presumption? If so, does someone have a clever work-around? I see this as something that is just plain broken. -- // Sorc Kirishi sorc@edsr.eds.com or ...!uunet!edsr!sorc
ecl2v@opal.cs.Virginia.EDU (Edmond C. Loyot) (06/23/91)
The ARM says that what you want to do is legal. Consider this example from
page 189 of the ARM:
class X {
typedef int I;
I a;
};
I b; // error
However when I run it through my 2.0 C++ compiler, it does not flag the error.
I think this is a throwback to the days of 1.2 when type names
(including classes) declared in a class where in the global scope. This
is definately an
error, but was probably allowed for backward compatability (my 2.0 compiler is
based on the ATT 2.0 compiler). I can't think of a work around.
Ed
steve@taumet.com (Stephen Clamage) (06/23/91)
ecl2v@opal.cs.Virginia.EDU (Edmond C. Loyot) writes: >The ARM says that what you want to do is legal. Consider this example from >page 189 of the ARM: [ example of typedef in a class ] >However when I run it through my 2.0 C++ compiler, it does not flag the error. >I think this is a throwback to the days of 1.2 when type names >(including classes) declared in a class where in the global scope... Nested types were introduced with version AT&T C++ 2.1. Up through 2.0, a type defined in a class was exported to the outer scope. In fact, AT&T 2.1 is a compromise between local and exported interpretation of nested types. AT&T 2.1 example: struct A { ... struct B { ... }; // exported to global }; struct B { ... }; // ERROR -- B already defined struct E { ... }; struct D { ... struct E { ... }; // local to D }; I assume this compromise is to allow existing code to continue to work, while allowing new code with nested types to be written. What I show in this example violates both the ARM and earlier language definitions! The ARM is for the post-2.1 brave new world. -- Steve Clamage, TauMetric Corp, steve@taumet.com