I want to use a library (nlopt) that has a function set_min_objective which takes a pointer to a numerical function myfunc and find its minimum. I would like to create a class that will contain a suitably initialized member function. set_min_objective would then find an optimum in a specific instance (myP in the example below). The call sequence is:
opt.set_min_objective(myfunc, NULL);
and I would like to use something like:
opt.set_min_objective(myP.f, NULL);
the error I get when compiling this is:
main.cpp: In function 'int main()':
main.cpp:79:34: error: no matching function for call to 'nlopt::opt::set_min_objective(<unresolved overloaded function type>, NULL)'
../lib/nlopt.hpp:335:10: note: candidates are: void nlopt::opt::set_min_objective(double (*)(unsigned int, const double*, double*, void*), void*)
../lib/nlopt.hpp:342:10: note: void nlopt::opt::set_min_objective(double (*)(const std::vector<double>&, std::vector<double>&, void*), void*)
../lib/nlopt.hpp:368:10: note: void nlopt::opt::set_min_objective(double (*)(unsigned int, const double*, double*, void*), void*, void* (*)(void*), void* (*)(void*))
What would be the simplest solution to have set_min_objective accepts myP.f as a normal pointer to function ? Note that myP.f and myfunc have the same arguments and return value types.
Thank you,
JD