Topic: derived enums


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/28
Raw View
In article nhf@boson.epita.fr, Loic Tregan@epita.fr (tregan_l) writes:
>
> I would like to derive an enum ;

You don't really need to, since you can extend an enum:

enum spiciness { extramild=100, medium=1000, extrahot=3000 };

Type "spiciness" can take on any value from 0 through 4095, so we
can later add, for example,
 const spiciness mild = (spicyness) 500;
 const spiciness hot  = (spicyness)2000;
 const spiciness WOW  = (spicyness)4000;
and so on. Even as class members these can be made static const, and
used in the same way as enumerators.

---
Steve Clamage, stephen.clamage@eng.sun.com