non-integral enums?

Unknown W. Brackets unknown at simplemachines.org
Fri Feb 24 20:47:20 PST 2006


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