schmidt@crimee.ics.uci.edu (01/03/89)
Hi,
I would really appreciate it if someone would clarify the following
obscure C++ point regarding the scope of enumerated types declared in
the public section of structs and/or classes.
Here is some code illustrating my question:
----------------------------------------
struct foo {
enum { FOO, BAR };
};
main ( ) {
int i = foo::FOO;
}
----------------------------------------
This example is derived from code presented on page 310 of Stroustrup
and Lippman's article regarding ``Pointers to Class Members in C++,''
specifically the last line of code on that page:
MyScreen.pmfSet(Screen::HEIGHT);
where HEIGHT was declared as an anonymous enumerated type literal in
the public section of class Screen:
class Screen {
public:
enum { WIDTH, HEIGHT };
// ...
}
Unfortunately, cfront 1.2.1 doesn't like either my example, nor the
code from the article, complaining that:
----------------------------------------
"foo.C", line 7: error: foo::FOO is private
1 error
----------------------------------------
( a rather strange error message for a struct! )
In any case, my question is of course, is the above code now
considered valid C++?
In a similar vein, should the following also be considered correct?
----------------------------------------
struct foo {
enum { FOO, BAR };
};
main ( ) {
int i = FOO; // note the lack of a qualifying context for FOO
}
----------------------------------------
My guess would be *no*, but I'm curious to know for sure.
thanks,
Doug Schmidt
--
schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente.
office: (714) 856-4043 | Per me si va nell'eterno dolore.
| Per me si va tra la perduta gente.
| Lasciate ogni speranza o voi ch'entrate.