Classes as enums in D?
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 30 00:07:58 PST 2015
On Monday, 30 November 2015 at 07:58:43 UTC, Andrew LaChance
wrote:
>
> Oh interesting. So you are saying I could have a struct
> WhiteKey {...} and then an enum that extends WhiteKey?
enums can't *extend* anything. You can do this:
struct WhiteKeyS {
immutable int halfStepsToPrevious;
immutable int halfStepsToNext;
}
enum WhiteKey {
A = WhiteKeyS(2, 2),
B = WhiteKeyS(2, 1),
C = WhiteKeyS(1, 2)
}
void main() {
import std.stdio;
writeln(WhiteKey.A.halfStepsToPrevious);
}
More information about the Digitalmars-d-learn
mailing list