[Dlang] Delegate Syntax Question

Jack via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 10 06:32:02 PST 2016


Hello. So I was trying to pass a delegate as an argument in a 
function and was wondering if I'm writing the correct code for it.

You see my code is :


//////////////////////////////////////////


class Foo()
{
  void bar()
  {
  writeln("Hello World");
  }
}

class Bar()
{

void delegate() action;

   void setAction(void delegate() dele)
   {
    action = dele;
   }

}

void main()
{
Foo foo = new Foo();
Bar bar = new Bar();
bar.setAction(&foo.bar);
bar.action();
}

/////////////////////////////////////////

Is this correct? Because I've been having trouble calling the 
delegate when passing the method and I read many documentation 
concerning function and delegates. I'm just confused. 
(Disclaimer: My code's pattern is the same as above but it's not 
really my exact code)


More information about the Digitalmars-d-learn mailing list