Why isn't this expression const?
Silverling
este_aqui_ at hotmail.com.remove.underscores
Wed May 9 15:10:06 PDT 2007
Brian Palmer Wrote:
> This code won't compile:
>
> struct Vector3 { float x,y,z; }
> const Vector3 ROT_FORCE_CCW = {0, 400_000, 0};
> const Vector3 ROT_FORCE_CW = {0, ROT_FORCE_CCW.y*-1, 0};
>
> That last line gives me the error:
>
> Error: non-constant expression *((& ROT_FORCE_CCW+4)) * -1.0e+0F
>
> Strangely, I can do the equivalent three lines with basic types like ints just fine, but I can't get this struct initialization to work. Am I doing something wrong, or is it just lack of compiler smarts? I'm using (gdc 0.23, using dmd 1.007)
Try
const Vector3 ROT_FORCE_CCW = [0, 400_000, 0];
const Vector3 ROT_FORCE_CW = [0, ROT_FORCE_CCW.y*-1, 0];
That's how you init an array. I assume that Vector3 is an alias for float[3].
More information about the Digitalmars-d-learn
mailing list