real simple delegate question.

WhatMeWorry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 19 11:33:37 PDT 2017


On Friday, 18 August 2017 at 20:39:38 UTC, angel wrote:
> On Friday, 18 August 2017 at 02:38:15 UTC, WhatMeForget wrote:
>> [...]
>
> This actually appears correct ...
> The 1-st example:
> Each call to makeCalculator() increments a static (i.e. shared 
> among all makeCalculator() instances) variable - context.
> In addition, makeCalculator() generates a random variable.
> Whereas the delegate merely captures these variables, and the 
> displayed results reflect this.
>
> The 2-nd example:
> There is a single call to makeCalculator().
> After this call, context == 1, randy == _apparently 2_.
> Now the delegate, as has already been said, merely captures 
> these values, so consecutive calls do not change the result.

Thanks. So,
auto calculator = makeCalculator();
is the actual call of the delegate? "Delegate is function pointer 
with context"
But what is
...calculator(0));

Or maybe another approach would be to ask, what type is the 
compiler replacing auto with.






More information about the Digitalmars-d-learn mailing list