R
Ralf Goertz
Hi,
I have a numerical C library for function fitting. It defines a function
extern "C" void fit(
void (*func) (double *p, double *hx),
double *p, double *x);
and I want to use it in a class
class foo
{
public:
double *par,*val;
...
void eval(double*,double*) {...};
void do_fitting()
{
fit(&eval,par,val); (*)
}
};
However, the compiler complains at line (*) that the standard doesn't
allow function pointers of class functions to be used in that way. If
"eval" is declared outside foo it works fine. But I think that's a bad
design since everthing should take place in the class foo. At the moment
I use a wrapper function defined outside foo that just calls foo::eval.
void wrapper(double *p, double *x)
{
f->eval(p,x);
}
where f is a globally defined pointer to an instance of foo. I consider
this a bad design, too, but I don't know how to do it better. Why is it
not allowed to do it in the intended way and what would be a good work
around?
Ralf
I have a numerical C library for function fitting. It defines a function
extern "C" void fit(
void (*func) (double *p, double *hx),
double *p, double *x);
and I want to use it in a class
class foo
{
public:
double *par,*val;
...
void eval(double*,double*) {...};
void do_fitting()
{
fit(&eval,par,val); (*)
}
};
However, the compiler complains at line (*) that the standard doesn't
allow function pointers of class functions to be used in that way. If
"eval" is declared outside foo it works fine. But I think that's a bad
design since everthing should take place in the class foo. At the moment
I use a wrapper function defined outside foo that just calls foo::eval.
void wrapper(double *p, double *x)
{
f->eval(p,x);
}
where f is a globally defined pointer to an instance of foo. I consider
this a bad design, too, but I don't know how to do it better. Why is it
not allowed to do it in the intended way and what would be a good work
around?
Ralf