Hi,

Is there a reason why I cannot compile the following code:

module test;

struct Test {
    int delegate(int) f;
}

Test s = Test((int x) { return x + 1; });

void main(string[] args) {
    return;
}

dmd 2.057 says:

test.d(7): Error: non-constant expression cast(int delegate(int))delegate pure
nothrow @safe int(int x)
{
return x + 1;
}

?

This is simple example; what I want to do is to create a global variable
containing a structure with some ad-hoc defined functions. The compiler
complains that it "cannot evaluate .... at compile time". I think this could
be solved by defining a function returning needed structure, but I think this
is cumbersome and inconvenient.

Best regards,
Vladimir Matveev.

Reply via email to