Code example for function/delegate as template argument ?

chmike via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 4 04:19:59 PDT 2016


I think you misunderstood the second question.

Here is another attempt with an example.

// function accepting a function as argument
void foo(function void fg(int)) {
     fg(5);
}

// A class with a none static method with the same signature as 
the argument function of foo
class Bar {
     void fizz(int a) { writefln("Arg: %s", a); }
}

// An instance of class Bar
auto bar = new Bar;

// Calling foo by passing bar and the method fizz so that 
bar.fizz() is called when foo calls fg
foo( ??? );

Does the argument type need to be a delegate ?


More information about the Digitalmars-d-learn mailing list