passing function to Fitmrq


Ryan Ringle
02-08-2008, 01:44 PM
Greetings,
I'm having difficulties passing a function to the Fitmrq routine. I have a class called fitTools where I have defined the fit function ( a simple Gaussian for testing called gaussFunc) and fit method. My question is how do I pass the function within the fit method? Doing

void fitTools::gaussFunc(...)
{
...
}

vector<double> fitTools::fitGaussFunc(...)
{
...
Fitmrq myfit(x,y,sd,a,gaussFunc,1e-3);
...
}

return a "no matching function call.." error upon compilation and lists gaussFunc as an <unknown type>. I've also tried making a pointer to the method within the fit method and passing that, to no avail. I'm assuming it's a problem with syntax that I don't understand. Any help would be appreciated.

Ryan

davekw7x
02-08-2008, 11:18 PM
I'm having difficulties ...

A pointer to a non-static member function has an implicit parameter that makes the pointer not compatible with pointers to regular functions with the same parameter list and return type, and can't be cast to be a pointer to a regular function.

Short answer: Declare gaussFunc static:


class fitTools {
.
.
.
static void gaussFunc(const Doub, VecDoub_I &, Doub &, VecDoub_O &);
.
.
.
vector<double> fitGaussFunc(...)
.
.
.
};

void fitTools::gaussFunc(const Doub x, VecDoub_I &a, Doub &y, VecDoub_O &dyda)
{
.
.
.
}

vector<double> fitTools::fitGaussFunc(...)
{
.
.
.

Fitmrq myfit(x,y,sd,a,gaussFunc,1e-3);
.
.
.
}






Regards,

Dave

Ryan Ringle
02-09-2008, 05:33 PM
Thanks a lot, it worked like a charm!

Ryan