Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!zaphod.mps.ohio-state.edu!rpi!ispd-newsserver!atexnet!plantagenet!berczuk From: berczuk@plantagenet.BU.EDU (Steve Berczuk) Newsgroups: comp.lang.c++ Subject: Appropriate use of ENUMs Message-ID: <5415@atexnet.Atex.Kodak.COM> Date: 23 May 91 19:37:39 GMT Sender: news@Atex.Kodak.COM Reply-To: berczuk@pbtc.kodak.com (Steve Berczuk) Organization: Eastman Kodak Boston Technology Center Lines: 46 I'd appreciate some comment on the following question that has been bounding around over here: 2 programmers are working on a given application and one defines the enum: enum STATUS{ GOOD,OK,FAIL} the other: enum GOOD_STATUS{GOOD,OK} ther are also (member ) functions defined as follows STATUS myFunc(..) GOOD_STATUS myOtheFunc(...) if the the two enumus are compiled together you'll get an error because GOOD and OK are in 2 enums, There are a number of ways to resolve this, the cleanest of which is to define each enum in a class scope: class foo{ enum STATUS{ GOOD,OK,FAIL} } class foo2{ enum GOOD_STATUS{GOOD,OK} } and the particular enum referred to can be resolved using the scoping operator (with the resulting awkward syntax) THE QUESTION, HOWEVER, is: is it appropriate to use the enum mechanism to limit the return values to a compiler checkable range, or should one enum STATUS be defined to encompass the whole range of codes and the return value be limited by range checking. (assume that GOOD, OK,and FAIl relate to the same status codes) one arguement is that thischecking of scope of return value using enums is a feature of the language. the other is the counter example of a function defined as follows: int foo(y) { //returns an integer GREATER than 0. } // ie the fact the the return has a limited range is a requirement that should be tested. thanks in advance for your opinions.