Copying a variable state in a delegate literal definition

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Sep 2 14:52:41 PDT 2011


On 9/2/11, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> Am I missing something, or is it this simple?
>
> void appendMenuButton()
> {
>     static size_t menuIndex;
>     auto frameIndex = menuIndex++;
>     button.connect!(Signal.MouseClick) = { this.showMenu(frameIndex); };
> }
>
> -Steve
>

Actually It *is* that simple. Which is odd because I swear I've tried
it once but it didn't work, and now it works again. Something has to
be messing with the compiler or my brain!


More information about the Digitalmars-d-learn mailing list