From 471442142878313716 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,e422f6e841d07a08 X-Google-Attributes: gidf78e5,public From: maxtal@Physics.usyd.edu.au (John Max Skaller) Subject: Re: "Subclassing" Enums Date: 1995/03/30 Message-ID: #1/1 X-Deja-AN: 100543939 sender: news@ucc.su.OZ.AU references: <3l72bh$8tf@crchh299.bnr.ca> <3l75on$b9l@engnews2.Eng.Sun.COM> organization: School of Physics, University of Sydney, Australia newsgroups: comp.std.c++ In article <3l75on$b9l@engnews2.Eng.Sun.COM>, Steve Clamage wrote: >The new rule about const static members makes these work even more like >enums in classes, including having class scope: > > class base { > enum error_code { informational=0, warning=1000, > error=2000, fatal=3000 }; > }; > > class derived : public base { > static const error_code weekday = 100; > ... > }; And further to my previous comments -- this code is wrong. There is no implicit conversion from int to an enum type. So you'd have to write: static const error_code weekday = error_code(100); And now a technicality makes this illegal. error_code(100) isn't a constant expression. The reason is that enumerations are NOT arithmetic types, and only conversions to arithmetic types are permitted in constant expressions. (I think that is a bug in the WP). You can use an enumerator in a constant expression because even though it is not an arithemtic type it is explicitly allowed. But it is completely useless, becaus ethe conversion to an integral type is not a conversion from an arithmetic type to an arithmentic type -- the only kind permitted in constant expressions. -- JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au Maxtal Pty Ltd, 81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21 NSW 2037, AUSTRALIA Phone: 61-2-566-2189