How to hand in a closure variable
Dicebot
public at dicebot.lv
Mon Mar 24 09:56:33 PDT 2014
On Monday, 24 March 2014 at 16:40:55 UTC, Bienlein wrote:
> Now I want the closure (aka delegate) to have a closure
> variable:
>
> int a = 7;
> int delegate(int) dg = { value => return value + a + 3; };
> auto result = dg(123);
>
> Unhappily, the code above doesn't compile. Tried various
> things, looked for samples on the D hompepage and in the book
> by Çehreli, but had no luck.
>
> Some hints appreciated.
> Thanks, Bienlein
auto dg = (int value) { return value + a + 3; };
or short-hand form:
auto dg = (int value) => value + a + 3;
More information about the Digitalmars-d-learn
mailing list