Bug 3999 and 4261

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Aug 31 19:19:59 PDT 2010


This whole enum thing is making my head explode out of confusion. I
thought having a tag was just supossed to be used as a namespace for
enumerated values. E.g.:

enum { red = 1, green, blue }
...
if (getValue() == green) {
    do..
}

and:

enum Tagged { red = 1, green, blue }
...
if (getValue() == Tagged.green) {  // safer version
    do..
}

That is all that I thought enums are useful for. But apparently an
enum is a type and you can instantiate it.... and I don't even know
what an enum is anymore. I'll just stay out of this discussion for
now, lol. :)

> I agree, and I have never said I want to disallow it. You can cast those FOO, BAR, etc implicitly to int. It's the example V2 I have shown, no error there:
>
> enum V1 = 10;
> enum { V2 = 20 }
> enum Foo { V3 }
> void main() {
>    assert(V1 == 10);    // OK
>    assert(V2 == 20);    // OK
>    assert(Foo.V3 == 0); // ERROR, type mismatch
> }
>
> Thank you for your doubts and questions, they help me express better what I meant. It seems I was not clear enough at the beginning.
>
> Bye,
> bearophile
>


More information about the Digitalmars-d mailing list