Why isn't opMul allowed in a const expression
torhu
no at spam.invalid
Tue Nov 20 09:29:26 PST 2007
Steven Schveighoffer wrote:
> I added:
>
> static X tmpOpMul(X x, int y)
> {
> return X(x.value * y);
> }
>
> To X, and I can do:
>
> static myX4 = X.tmpOpMul(myX, 4);
>
> without error. I don't see how this is any different than calling opMul.
> It should be evaluatable at compile time, no?
>
For initializing a constant you need a compile-time value.
From the docs about compile-time functions:
"4. the function may not be a non-static member, i.e. it may not have a
this pointer"
More information about the Digitalmars-d
mailing list