相关疑难解决方法(0)

将std :: bind转换为函数指针

我有一个第三方库,它有一个方法,将函数指针作为第一个参数:

int third_party_method(void (*func)(double*, double*, int, int, double*), ...);
Run Code Online (Sandbox Code Playgroud)

我想传递一个指向类声明如下的方法的指针:

class TestClass
{
    public:
        void myFunction (double*, double*, int, int, void*);
Run Code Online (Sandbox Code Playgroud)

我试图传递这个函数如下:

TestClass* tc = new TestClass();
using namespace std::placeholders;
third_party_method(std::bind(&TestClass::myFunction, tc, _1, _2, _3, _4, _5), ...);
Run Code Online (Sandbox Code Playgroud)

但是,这不编译:

Conversion of parameter 1 from 'std::tr1::_Bind<_Result_type,_Ret,_BindN>' to 'void (__cdecl *)(double *,double *,int,int,void *)' is not possible
with
[
    _Result_type=void,
    _Ret=void,
    _BindN=std::tr1::_Bind6<std::tr1::_Callable_pmf<void (__thiscall TestClass::* const )(double *,double *,int,int,void *),TestClass,false>,TestClass *,std::tr1::_Ph<1>,std::tr1::_Ph<2>,std::tr1::_Ph<3>,std::tr1::_Ph<4>,std::tr1::_Ph<5>>
]
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将成员传递给函数吗?

c++ function-pointers

44
推荐指数
3
解决办法
3万
查看次数

标签 统计

c++ ×1

function-pointers ×1