https://tour.dlang.org/tour/en/basics/delegates
This is so simple. What is D complaining about?
Should this also work with a Template, as shown?
import std.stdio;
void main()
{
// auto add(T)(T lhs, T rhs)
// {
// return lhs + rhs;
// }
int add(int lhs, int rhs) {
return lhs + rhs;
}
int doSomething(int function(int, int) doer)
{
// call passed function
return doer(5, 6);
}
doSomething(&add);
}
Console output:
c:\dev\D\D_templates_tutorial\toy1\source\app.d(20): Error: function `doSomething` is not callable using argument types `(int delegate(int lhs, int rhs) pure nothrow @nogc @safe)`
doSomething(&add);
^
c:\dev\D\D_templates_tutorial\toy1\source\app.d(20): cannot pass argument `&add` of type `int delegate(int lhs, int rhs) pure nothrow @nogc @safe` to parameter `int function(int, int) doer`
c:\dev\D\D_templates_tutorial\toy1\source\app.d(14): `app.main.doSomething(int function(int, int) doer)` declared here
int doSomething(int function(int, int) doer)
^