D2:函数指针不会编译

Naf*_*ees 3 pointers d

我正在尝试在DLang中使用函数指针(函数指针),但它不会编译.制作函数指针的网上所有代码对我来说都不起作用.这是我的代码:

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;
};
Run Code Online (Sandbox Code Playgroud)

我在ubuntu上使用dmd2.

wel*_*urm 6

divide显然是一个代表,而不是一个功能.您可以使用委托的列表,而不是(只需更换functiondelegate),或确保您的函数是不是委托.

对于后者:看起来divide是一个类方法,而不是普通函数.制作它static或将它移到课堂体外.