Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!sun-barr!newstop!sun!plx!johnc From: johnc@plx.UUCP (John C.) Newsgroups: comp.lang.c++ Subject: Re: enums Keywords: enum subrange array index Message-ID: <2205@plx.UUCP> Date: 11 Jan 90 17:59:48 GMT References: <963@rna.UUCP> <10197@microsoft.UUCP> <9925@ardent.UUCP> <10215@microsoft.UUCP> Reply-To: johnc@plx.UUCP (John Ciccarelli) Organization: Plexus Software, Santa Clara, CA Lines: 32 Summary: Sender: Followup-To: Having used full-featured enums (and subranges -- *sigh* ) in other languages, this debate about "should you be prevented from assigning an int to an enum without a cast" seems like needless hand-wringing. IMHO, *of course* you shouldn't be allowed to do this without a cast (this is to offend some diehard original-C types I know). But if I have (pardon the loose syntax): enum Fruit { Apple, Orange, Banana, Lemon } enum Vegetable { Tomato [<==debatable ;-)], Squash, Rutabaga } ... Fruit fruit; Vegetable veg; then the assignment 'fruit = 1' is as much an error as 'fruit = Squash' or 'fruit = veg'. By 'full-featured' enums, I meant (for one thing) the ability (in other languages) to declare an array with an 'enum' subscript: int fruitPrice[ Fruit ]; This is so simple but so powerful. In the "C++ Primer" I didn't see a way to do this, probably because it presupposes arrays with non-zero base subscripts, which I'm pretty sure C++ also lacks. Both features are conceptually simple but greatly improve readability and robustness. Ditto subrange types. ...My three wishes for today. (Are the C++ architects listening?) /John Ciccarelli, Plexus Software (johnc@plx.uucp || ...sun!plx!johnc) [opinions mine]