假设我有这个:
void func(WCHAR* pythonStatement) {
// Do something with pythonStatement
}
Run Code Online (Sandbox Code Playgroud)
我需要将它转换为void function(void),如下所示:
bind(func, TEXT("console.write('test')"))
Run Code Online (Sandbox Code Playgroud)
现在我有这样的结构:
typedef void (__cdecl * PFUNCPLUGINCMD)();
struct FuncItem {
PFUNCPLUGINCMD pFunc;
// ...
};
Run Code Online (Sandbox Code Playgroud)
如何设置我的struct的pFunc bind(func, "something")?绑定返回lambda_functor而不是函数指针,那么如何将此函子转换为函数指针?
谢谢.
结束使用包装"解决方案"(GitHub)
我认为你不能,除非你使得lamba_functor成为一个全局变量.
在这种情况下,您可以声明一个调用它的函数:
void uglyWorkaround() {
globalLambdaFunctor();
}
Run Code Online (Sandbox Code Playgroud)
并设置pFunc为uglyWorkaround().
编辑
只是一个旁注:如果你将静态文本绑定到函数调用,你可以完全省略bind()调用并写入:
void wrapper() {
func(TEXT("console.write('test')"));
}
Run Code Online (Sandbox Code Playgroud)
并设置pFunc为wrapper().