How to make delegate refer to itself?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Nov 23 15:28:03 PST 2013


On Sun, Nov 24, 2013 at 12:24:53AM +0100, Philippe Sigaud wrote:
> On Sat, Nov 23, 2013 at 11:57 PM, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:
> > void delegate(Event) dg = (Event e) {
> >                 if (e == ...)
> >                         queue.remove(dg); // NG: Still complains 'dg' isn't defined
> >         };
> >         queue.register(dg);
> 
> Did you try this?
> 
> void delegate(Event) dg;
> 
> dg = (Event e) {
>     if (e == ...)
>         queue.remove(dg); // NG: Still complains 'dg' isn't defined
> };
> 
> queue.register(dg);

You're right, separating the dg declaration from the body of the
delegate fixes the problem.

But still, it's rather ugly. I wish there were a way for a delegate to
refer to itself.


T

-- 
Frank disagreement binds closer than feigned agreement.


More information about the Digitalmars-d-learn mailing list