【发布时间】:2018-11-26 21:36:43
【问题描述】:
在 C++ 中, 对于一个接收返回类型为 void 的函数指针的函数,例如:
void TakesFun(Func<void ()> fun ){
fun();
}
上面的函数可以通过这些方式调用
//if foo is a function returning void but is declared in global space and not part of another class
TakesFun(bind(foo));
//if foo is a function returning void but is declared in class called ClassX and the function is required to be called for object "obj".
TakesFun(bind(ClassX::foo, obj));
//if foo is a function taking an integer as argument and returning void but is declared in class called ClassX and the function is required to be called for object "obj".
TakesFun(bind(ClassX::foo, obj, 5)); //5 is the argument supplied to function foo
您能帮我为 3 个类似的函数调用编写 C# 代码吗?我尝试阅读 Delegates,但示例并未涵盖上述所有 3 种情况。
【问题讨论】:
标签: c# c++ delegates function-pointers