initializer for array of function literals

Adrian Matoga epi at atari8.info
Sun Oct 31 03:16:47 PDT 2010


Sorry, I didn't included main() just because an empty one was enough.
I know it can be done with pointers to static functions, but I'd prefer 
syntax with array of function literals for better readability in one 
particular case I'm playing with now.
Anyway, thanks.


On 2010-10-31 03:13, bearophile wrote:
> 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