enum with classes/structs
bearophile
bearophileHUGS at lycos.com
Thu Mar 10 11:28:04 PST 2011
useo:
> is it possible to declare a enum where all entries are instances of a
> class (or struct), like the following:
I don't think so. Enums are compile-time constants.
This code doesn't compile:
class A {
this(uint i) {}
}
enum myEnum : A {
entry1 = new A(0),
entry2 = new A(1)
}
void main() {}
It's important to understand that in D OOP and procedural/C-style features are often separated. typedef didn't work well with OOP. Don't mix things that are not meant to be mixed.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list