lundi 2 novembre 2015

convert double (class::*)(const gsl_vector*, void*) to double (*)(const_gsl vector*,void*) [duplicate]

This question already has an answer here:

I'm minimizing a function min_fun(const gsl_vector*, void*) with the gsl minimizer gsl_multimin_fminimizer_nmsimplex2. To give this one the function to minimize you define gsl_multimin_function minex_func;

and then minex_func.f = min_fun ; minex_func.n = 3; (The numbers of variables to minimize and the number of elements of const gsl_vector) minex_func.par = par; (the void* in which you give the function all parameters which are constant for one function call)

When I had both in my main file (the gsl minimization directly in my main() and min_fun as a function defined in my main file) it all worked like this. Now I want to take this routine in a Function in a Class called Potential so that I can just have a one line call for the minimizing process in my main file.

So I now define Potential::Minimize() in which I have the exact same call as before for the minimzation. I also define Potential::min_fun(const gsl_vector*, void*) which is the same as the min_fun before.

Depending on my versions for minex_func.f = I get different errors :

minex_func.f = Potential::min_fun ; -> this one leads to error: cannot convert ‘Potential::min_fun’ from type ‘double (Potential::)(const gsl_vector*, void*)’ to type ‘double ()(const gsl_vector, void*)’

minex_func.f = &Potential::min_fun; -> Here we get error: cannot convert ‘double (Potential::)(const gsl_vector, void*)’ to ‘double ()(const gsl_vector, void*)’

minex_func.f = min_fun; Here we get error: cannot convert ‘Potential::min_fun’ from type ‘double (Potential::)(const gsl_vector*, void*)’ to type ‘double ()(const gsl_vector, void*)

If I use Potential *modfunc = new Potential;

and then

minex_func.f = modfunc->min_fun; I get error: cannot convert ‘Potential::min_fun’ from type ‘double (Potential::)(const gsl_vector*, void*)’ to type ‘double ()(const gsl_vector, void*)’

Can someone explain me how to get it to work and what the difference is between the Statement directly in the main file and in the Class Definition?

Cheers, Bär.

Aucun commentaire:

Enregistrer un commentaire