Funktions-Pointer
-
Ich möchte das Package http://devernay.free.fr/hacks/cminpack.html verwenden, habe aber Probleme, es in meine Klasse einzubinden.
Das Interface aus cminpack.h lautet:
typedef int (*minpack_func_mn)(void *p, int m, int n, const double *x, double *fvec, int iflag ); int lmdif1 ( minpack_func_mn fcn, void *p, int m, int n, double *x, double *fvec, double tol, int *iwa, double *wa, int lwa );In meiner Klasse sieht es so aus:
void MyClass::opt() { int m, n, info, lwa, iwa[3]; double tol, fnorm, x[3], fvec[15], wa[75]; m = 15; n = 3; x[0] = 1.e0; x[1] = 1.e0; x[2] = 1.e0; lwa = 75; tol = sqrt(dpmpar(1)); info = lmdif1(&MyClass::errorFcn, 0, m, n, x, fvec, tol, iwa, wa, lwa); } int MyClass::errorFcn(void *p, int m, int n, const double *x, double *fvec, int iflag) { return 0; }Beim Compilieren erhalte ich den Fehler:
error: cannot convert ‘int (MyClass::)(void, int, int, const double*, double*, int)’ to ‘int ()(void, int, int, const double*, double*, int)’ for argument ‘1’ to ‘int lmdif1(int ()(void, int, int, const double*, double*, int), void*, int, int, double*, double*, double, int*, double*, int)’
Es gibt wohl ein Problem beim Funktions-Pointer. Kann mir bitte jemand helfen?
-
Mach errorFcn statisch oder als freie Funktion.
-
Vielen Dank!