问题描述
假设我有这个:
void func(WCHAR * pythonStatement){
//使用pythonStatement
}
我需要将其转换为void function / p>
bind(func,TEXT(console.write('test')))
现在我有这样的结构:
typedef void(__cdecl * PFUNCPLUGINCMD)();
struct FuncItem {
PFUNCPLUGINCMD pFunc;
// ...
};
如何设置我的struct的pFunc为
bind(func,东西)
? Bind返回lambda_functor而不是函数指针,那么如何将这个函子转换为函数指针?
谢谢。
使用(GitHub)
解决方案我认为你不能,除非你lamba_functor一个全局变量。
在这种情况下,你可以声明一个函数来调用它:
void uglyWorkaround(){
globalLambdaFunctor();
}
并设置
pFunc
到uglyWorkaround()
。
EDIT
sidenote:如果你绑定静态文本到函数调用,你可以完全省略bind()
调用,只写:void wrapper(){
func(TEXT(console.write('test')));
}
并设置
pFunc
到wrapper()
。Suppose I have this:
void func(WCHAR* pythonStatement) { // Do something with pythonStatement }
And I need to convert it to void function(void) like this:
bind(func, TEXT("console.write('test')"))
Now I have struct like this:
typedef void (__cdecl * PFUNCPLUGINCMD)(); struct FuncItem { PFUNCPLUGINCMD pFunc; // ... };
How can I set the pFunc of my struct to
bind(func, "something")
? Bind returns lambda_functor not a function pointer, so how can I cast this functor to function pointer?Thanks.
Ended up using the wrapping "solution" (GitHub)
解决方案I think that you can't, unless you make the resulting lamba_functor a global variable.
In that case, you could declare a function that invokes it:
void uglyWorkaround() { globalLambdaFunctor(); }
and set
pFunc
touglyWorkaround()
.EDIT
Just a sidenote: if you are binding static text to the function call, you may completely omitbind()
call and write just:void wrapper() { func(TEXT("console.write('test')")); }
and set
pFunc
towrapper()
.这篇关于如何转换或转换boost绑定到C函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!