Hey,
How can I get this one work?
There is a class which gets a function f as an argument. This function is combined with other ones to a new function diff. So far it's fine.
Now I want to pass this new function as a reference for further usage. I just can't get around this error the compiler gives me: " cannot convert ‘double (test::*)(double)’ to ‘double (*)(double)’ in assignment "
I even don't understand the problem at all.
Code:
//provides a function (diff) which gives the difference from an inputfuntion to zero.
class test
{
public:
test() {diff = &standardFunc_;};
~test();
double (*diff)(double x);
void setFunc(double f(double x))
{
func_ = f;
diff = &test::calc_; //error: cannot convert ‘double (test::*)(double)’ to ‘double (*)(double)’ in assignment
};
private:
static double standardFunc_(double x) { return 0;}
double (*func_)(double x);
double calc_(double x)
{
return func_(x) - standardFunc_(x);
}
};
I need that for ceating an easy-to-use fit-interface for the gsl-library. For fitting I need to give some functions as refrences - but this doesn't work within a class .
Hope somebody can help
Christian