I'm trying to use function pointers in DLang (Pointer to function), but it wont compile. All the code on the web on making function pointers, doesn't work for me. This is my code:
tqvar function(tqlist)[string] procs;
procs["divide"] = ÷/// cannot implicitly convert expression (&this.divide) of type tqvar delegate(tqlist args) to tqvar function(tqlist) (QScript)
tqvar divide(tqlist args){
tqvar result;
result.ii = true;
result.d = args.read(0).d/args.read(1).d;
return result;
};
I'm using dmd2, on ubuntu.
divide
is apparently a delegate, not a function. You can either use a list of delegates instead (just replace function
with delegate
) or ensure your function is not a delegate.
For the latter: it looks like divide is a class method, not a plain function. Either make it static
or move it outside of the class body.