ubuntu 下使用 C++编程,调用 gsl 积分库,被积函数作为成员函数,定义如下:
double planning::f(double x, void * params) {
double alpha = *(double *)params; double f = pow(x, 4)*sin(0.3*x + 0.12194239*pow(x, 2)); return f; }
在另一个成员函数中拷贝该函数指针以调用积分计算函数,如下:
void planning::GpsCallback(const GpsImu7661::ivsensorgps::ConstPtr& in) {
gsl_set_error_handler_off(); gsl_integration_workspace * w= gsl_integration_workspace_alloc(1000); double result, error; double expected = -4.0; double alpha = 1.0; gsl_function F; //*****************************// F.function = &f; //F.function = &planning::f; F.params = α int fanhui = gsl_integration_qags(&F, 0, 82.16478, 0, 1e-7, 1000, w, &result,&error); if (0 == gsl_integration_qags(&F, 0, 82.16478, 0, 1e-7, 1000,w, &result, &error)){ printf("result = % .18f\n", result); printf("estimated error = % .18f\n", error); printf("intervals = %zu\n", w->size); } gsl_integration_workspace_free(w); }
*下语句报错如下: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.
百度错误之后修改为 F.function = &planning::f;
报错变成了:error: cannot convert ‘ double (planning::)(double, void)’ to ‘ double ()(double, void)’ in assignment
有没有在成员函数中调用过 gsl 函数库的大神,,有什么解决方法吗?
