initializer for array of function literals

bearophile bearophileHUGS at lycos.com
Sat Oct 30 20:13:18 PDT 2010


Adrian Matoga:

> I would appreciate if somebody explained to me why this code:
> 
> static void function(int a)[] foo = [ function (int a) { } ];
> 
> causes the following compile error:
> 
> test.d(2): Error: non-constant expression __funcliteral1

When you ask for questions like these, please if possible show a complete compilable program that includes a main().

This doesn't compile:

static void function(int a)[] foo = [function (int a) {}];
void main() {}


This works, but I don't know/remember what's the difference:

void f1(int a) {}
static void function(int a)[] foo = [&f1];
void main() {}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list