I have a third-party library which has a method that takes a function pointer as the first parameter:
int third_party_method(void (*func)(double*, double*, int, int, double*), ...);
I want to pass a pointer to a class' method that is declared as follows:
class TestClass
{
public:
void myFunction (double*, double*, int, int, void*);
I tried to pass this function as follows:
TestClass* tc = new TestClass();
using namespace std::placeholders;
third_party_method(std::bind(&TestClass::myFunction, tc, _1, _2, _3, _4, _5), ...);
However, this does not compile:
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>>
]
Is there any way I can pass the member to the function?
std::function
. Then you'll be able to bind thethis
pointer to a method, and pass it as a "function pointer" (functor). – Thorin