How to initialize static array member variable?
Sebastian Schuberth
sschuberth at gmail.com
Thu Sep 30 12:14:09 PDT 2010
Hi,
I'm still playing around with DMD 2.049 and my Vector struct. This
struct Vector(alias N,T)
{
static immutable Vector X=Vector(1,0,0);
this(T[N] v ...) {
data=v;
}
T data[N];
};
alias Vector!(3,float) Vec3f;
gives
Error 1 Error: Slice operation this.data[] = cast(const(float[]))v
cannot be evaluated at compile time main.d 6
I also tried simply
struct Vector(alias N,T)
{
static immutable Vector X=Vector(1,0,0);
this(T x,T y,T z) {
data[0]=x;
data[1]=y;
data[2]=z;
}
T data[N];
};
alias Vector!(3,float) Vec3f;
but that gives
Error 1 Error: Index assignment this.data[0u] = x is not yet supported
in CTFE main.d 6
Error 2 Error: Index assignment this.data[1u] = y is not yet supported
in CTFE main.d 7
Error 3 Error: Index assignment this.data[2u] = z is not yet supported
in CTFE main.d 8
Any other ideas how to introduce such an "X" constant?
Thanks.
--
Sebastian Schuberth
More information about the Digitalmars-d-learn
mailing list