Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tdatirv!sarima From: sarima@tdatirv.UUCP (Stanley Friesen) Newsgroups: comp.lang.c++ Subject: Re: Private Enumerations? Message-ID: <143@tdatirv.UUCP> Date: 6 Sep 90 22:37:46 GMT References: <15414@reed.UUCP> Reply-To: sarima@tdatirv.UUCP (Stanley Friesen) Organization: Teradata Corp., Irvine Lines: 39 In article <15414@reed.UUCP> minar@reed.bitnet (Nelson Minar) writes: >Is there a way, or should there be a way, to allow enumerations that have scope >only within their class? >For example: >class Boolean { >public: > enum boolEnum { false, true }; > boolEnum value; >} This is indeed quite legal, at least in version 2.x. And it does declare an enumeration that is a member of the class Boolean. >so then I could say >main() { > Boolean bool; > int foo; > bool.value = true; > foo = true; // ILLEGAL - out of scope >} Unfortunately, this is not how it works. As you have Boolean declared both assignments are 'illegal', and for the same reason - there is no identifier 'true' in scope in main(). The identifier 'true' is only in scope *within* the class Boolean, that is from member functions of Boolean or by using the scope resolution operator. Thus both of the following are legal: bool.value = Boolean::true; foo = Boolean::true; This is so because the enum is declared as public, making it publicly accessible. I know of no way to use this feature to get what you want, if you declare the enum private it is only usable in member and friend functions, making its use in main() illegal. ----------------- uunet!tdatirv!sarima (Stanley Friesen)