c++ - Conversion function from std::bind -
i receiving error when create new function using std::bind
, trying pass function.
my code looks like
#include <functional> using namespace std; typedef double (*t_function)(double t, double *y); double integrate_fmax(double s, bool(*t_max)(double t, double *y), void(*fce_min)(double s, double &t_0, double *y_0), t_function fce_max, double err, t_function *f_diff, int dim){...} void get_x1_x2(double &x1, double &x2, double(*fce)(double x), double mlt){...} double shoot_meth(double s1, double mlt, bool(*t_max)(double t, double *y), void(*fce_min)(double s, double &t_0, double *y_0), t_function fce_max, double err, t_function *f_diff, int dim){ double s2; auto fce_x = bind(integrate_fmax, placeholders::_1, t_max, fce_min, fce_max, err, f_diff, dim); get_x1_x2(s1, s2, fce_x, mlt); }
i receving error when try pass function fce_x
get_x1_x2
:
c2664: 'void get_x1_x2(double &,double &,double (__cdecl *)(double),double)' : cannot convert argument 3 'std::_bind<true,double,double (__cdecl *const )(double,bool (__cdecl *)(double,double *),void (__cdecl *)(double,double &,double *),t_function,double,t_function *,int),std::_ph<1> &,bool (__cdecl *&)(double,double *),void (__cdecl *&)(double,double &,double *),double (__cdecl *&)(double,double *),double &,t_function *&,int &>' 'double (__cdecl *)(double)'
but when tried double foo = fce_x(5)
no error.
i using microsoft visual studio 2013.
p.s. sorry ugly functions not sure error , simplifying help.
std::bind
not return function pointer. need use std::function
instead. because std::bind
guaranteed return can stored in std::function
. if replace
double(*fce)(double x)
with
std::function<double(double)> fce
it should work properly.
Comments
Post a Comment