On 13/02/13 08:26, Hershel Safer wrote: > l define a function myF() to compute f(x), and pass GSL a pointer to myF(). > The problem is that the compiler won't convert from "pointer to myF ()" to > the way that GSL declares the pointer. This is because C++ treats a > "pointer to member function" differently from how it treats a pointer to a > function that is not part of a class. I understand the C++ issue; I hope > that somebody on this list knows how to get around it.
It can be done. I wrote some C++ wrappers for GSL to avoid ever having to use alloc or free and to allow member functions in place of functions: http://sourceforge.net/projects/ccgsl/ This may be a lot more than you need. But the code for multimin_function.hpp should show you how you can do what you want. http://www.johndlamb.net/ccgsl/classgsl_1_1multimin_1_1function.html The code is designed to use member functions with a parameter gsl::vector& rather than gsl_vector*, but it should be reasonably straightforward to adapt it. If you use this kind of approach I’d recommend you use header files for all the wrappers so that the compiler can optimise away all the details. -- John D Lamb
