On Wednesday, 18 April 2018 at 01:58:40 UTC, arturg wrote:

is it this what you want?

   class A
   {
       int a;
       void delegate() onDraw;

       this(void delegate() dg)
       {
           onDraw = dg;
       }

       void drawText(string s)
       {
           s.writeln;
       }
   }

   void main()
   {
        A a;
a = new A((){ a.a = 5; a.drawText("test"); "drawing all".writeln; });
    }

but if you do A a = new A((){ a.a = 5; ...});
the dg cant capture 'a' yet.
so maybe it would be better to just do:
A a = new A;
a.onDraw = (){ a.drawText("test"); "draw rest".writeln; };

ah i see bauss already wrote the same.

some other aproach could be:

class Base
{
    final void draw()
    { drawSelf(); }

    abstract void drawSelf();
}

class A : Base
{
    override void drawSelf()
    { ... }
}

Reply via email to