On 01/14/2012 07:13 PM, Vladimir Matveev wrote:
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.
I think it should work. I have filed a bug report: http://d.puremagic.com/issues/show_bug.cgi?id=7298
