non-integral enums?

Chris Sauls ibisbasenji at gmail.com
Sun Feb 26 14:22:01 PST 2006


Actually any enum without an identifier just introduces constants into the current scope, 
as per the previously cited examples.  So in essence, an enum is just a collection of 
constants (of identical type) and an optional namespace to contain them, and a special 
rule that enum namespaces can be used as types.

-- Chris Nicholson-Sauls

Unknown W. Brackets wrote:
> Actually, isn't it more like a typedef (but not completely) and a 
> namespace?
> 
> In that case, you can do colors.red - you have to do this right now if 
> you want to use constants: (iirc)
> 
> static struct colors
> {
>    const int red = 1;
> }
> 
> But then it is an int, and implicit casting is not as described by 
> Thomas Kuehne.
> 
> -[Unknown]
> 
> 
>> On Sat, 25 Feb 2006 13:12:10 +1100, Wang Zhen <nehzgnaw at gmail.com> wrote:
>>
>>
>>
>> [snip]
>>
>>> How different is enum from constants then?
>>
>>
>> I agree. I thought enum were invented as a shorthand way of doing ...
>>
>>   const int red = 1,
>>             blue = 2,
>>             green = 3;
>>
>> Instead we can do 'enum colors { red, blue, green }'
>>
>> To saving the coder having to recalculate the 'enumerated' names when 
>> some were added or deleted.
>>
>>   const int red = 1,
>>             yellow = 2,
>>             blue = 3,
>>             green = 4;
>>
>> Instead we can do 'enum colors { red, yellow, blue, green }'
>>
>> Otherwise they are just constants of varying values.
>>
>> --Derek Parnell
>> Melbourne, Australia



More information about the Digitalmars-d mailing list