Casting to union type?
cc via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 26 04:39:11 PDT 2014
Ahh, thanks. Looks like encapsulating the union in a struct with
alias this gets the job done, and removes the need for overloads.
Neat.
struct vec2 {
union {
struct {
float x = 0.0f;
float y = 0.0f;
}
float[2] v;
}
this(float x, float y) {
this.x = x;
this.y = y;
}
this(float[v.length] f) {
v[0..length] = f[0..length];
}
alias v this;
}
More information about the Digitalmars-d-learn
mailing list