Initialising arrays at compile time
bearophile
bearophileHUGS at lycos.com
Sun Jan 2 06:16:41 PST 2011
Peter Alexander:
> Ok, someone put me out of my misery, I can't figure out for the life of
> me how to do this. Basically, I have a vector class and want enums for
> the zero vectors:
>
> struct Vec
> {
> this(real x, real y) { e[0] = x; e[1] = y; }
> real[2] e;
> enum Vec zero = Vec(0, 0);
> }
Is this good enough?
struct Vec {
double[2] e;
static enum Vec zero = Vec([0.0, 0.0]);
this(real x, real y) {
e[0] = x;
e[1] = y;
}
}
void main() {}
(I think that "enum" and "static enum" are the same thing.)
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list