Copying a variable state in a delegate literal definition

Timon Gehr timon.gehr at gmx.ch
Fri Sep 2 15:57:39 PDT 2011


On 09/02/2011 08:46 PM, Andrej Mitrovic wrote:
> Damn it looks like I've ran into some template bug as well.
>
> With this:
>      @property void connect(Signal signal = Signal.MouseClick)(void
> delegate() dg)
>      {
>          clickHandlers ~= dg;
>      }
>
> and a call like this:
> item.connect = { this.showMenu(0); };
>
> this crashes with an access violation. But if I change connect to be a
> regular function:
>      @property void connect(void delegate() dg)
>      {
>          clickHandlers ~= dg;
>      }
>
> Then it works properly. Hmmm...

What happens if you declare the function final?


More information about the Digitalmars-d-learn mailing list