[Dlang] Delegate Syntax Question

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 10 06:57:57 PST 2016


On 10.01.2016 15:32, Jack wrote:
> //////////////////////////////////////////
>
>
> class Foo()

Those parentheses make this a (zero parameter) class template. I suppose 
you just want a plain class. Drop them then.

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

ditto

> {
>
> 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)

Aside from the mentioned parentheses (and a missing import), 
everything's correct.


More information about the Digitalmars-d-learn mailing list