本文介绍了如何转换或转换boost绑定到C函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个:

  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 to uglyWorkaround().

EDIT
Just a sidenote: if you are binding static text to the function call, you may completely omit bind() call and write just:

void wrapper() {
    func(TEXT("console.write('test')"));
}

and set pFunc to wrapper().

这篇关于如何转换或转换boost绑定到C函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 01:17