Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!ub!uhura.cc.rochester.edu!rochester!kodak!islsun!cok From: cok@islsun.Kodak.COM (David Cok) Newsgroups: comp.lang.c++ Subject: Re: Operator "++" applied to enumeration types. Keywords: Zortech ++ enumeration Message-ID: <1991Mar18.021859.29394@kodak.kodak.com> Date: 18 Mar 91 02:18:59 GMT References: <23651@well.sf.ca.us> Sender: news@kodak.kodak.com Distribution: comp Organization: Eastman Kodak Co., Rochester, NY Lines: 38 In article <23651@well.sf.ca.us> nagle@well.sf.ca.us (John Nagle) writes: > > Is the operator "++" permitted on enumeration types in C++? >Zortech C++ 2.1 rejects it as a request for an invalid type conversion. >Zortech C 2.1 is quite happy with it, leading me to suspect this is >policy, not a bug. But Strostrup's book is silent on the subject. > > Actually, increment and decrement on enumeration types make more >sense than allowing addition of two values of the same enumeration >type. Consider > > enum color_t {red,blue,green,yellow}; > color_t lamp1, lamp2; > int i; > > lamp1 = red; // OK > lamp1++; // reasonable > lamp1 = red + green; // silly,hould be an error > lamp1 = red + 1; // better > i = lamp1 - lamp2; // difference is logically an integer > >But this is probably too radical for C++. > > > > > > > John Nagle See the ARM section 7.2 in which it is explicitly stated that the results of numeric computations cannot be assigned (even via ++) to a variable of an enumerated type. The basic reason is that the integer representation of the enumerated values may consist of something other than consecutive integers. David R. Cok Eastman Kodak Company cok@Kodak.COM