我尝试创建一个包装类来将 c 函数包装lmdif1
在库cminpack中
class CSolver
{
public:
void solve()
{
...
using namespace std::placeholders;
auto f = std::bind(&CSolver::fcn, this, _1, _2, _3, _4, _5, _6);
int32_t iRet = lmdif1(f, 0, m_iEqualCount, m_iUnknownVariableCount, x, fvec, tol, iwa, wa, lwa);
}
private:
int32_t fcn(void* p, int32_t m, int32_t n, const double* x, double* fvec,int iFlag)
{
....
}
};
编译错误:
error: cannot convert ‘std::_Bind<std::_Mem_fn<int (CSolver::*)(void*, int, int, const double*, double*, int)>(CSolver*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>, std::_Placeholder<4>, std::_Placeholder<5>, std::_Placeholder<6>)>’ to ‘cminpack_func_mn {aka int (*)(void*, int, int, const double*, double*, int)}’ for argument ‘1’ to ‘int lmdif1(cminpack_func_mn, void*, int, int, double*, double*, double, int*, double*, int)’
int32_t iRet = lmdif1(f, 0, m_iEqualCount, m_iUnknownVariableCount, x, fvec, tol, iwa, wa, lwa);
我该如何解决?
编辑:所以我将使用一个全局函数。谢谢你们。