D 如何将函数文本作为回调传递

D 如何将函数文本作为回调传递,d,D,以下是我试图做的: void x(function int(int) f){ f(555); } void main(){ x(function int(int q){ }); } 错误消息令人困惑: funcs.d(4): Error: basic type expected, not function funcs.d(4): Error: found 'int' when expecting '(' funcs.d(4): Error: basic type expec

以下是我试图做的:

void x(function int(int) f){
    f(555);
}

void main(){
    x(function int(int q){  });
}
错误消息令人困惑:

funcs.d(4): Error: basic type expected, not function
funcs.d(4): Error: found 'int' when expecting '('
funcs.d(4): Error: basic type expected, not (
funcs.d(4): Error: function declaration without return type. (Note that constructors are always named 'this')
funcs.d(4): Error: found 'f' when expecting ')'

我无法从这些错误消息中获得任何信息。

将返回类型与
x
中的
函数
关键字交换。出于某种原因,它们在文字上的作用正好相反。此外,您传递的函数不会返回任何内容,即使它应该返回

void x(int function(int) f){
    f(555);
}

void main(){
    x((int q){ return 0; });
    // or
    x(function int(int q){ return 0; });
    // or
    x(q => 0);
}