I am working on an optimization algorithm, in my algorithm, I need to use a function pointer to pass the function into the optimizer
the class definition:
class Downhill
{
public: //
Downhill(std::string fpath);
~Downhill();
void run();
private:
/*objfun will be passed to amoeba function by function pointer*/
float objfun1(float *p,int ndim);
float objfun2(float *p,int ndim);
float objfun3(float *p,int ndim);
void amoeba(float **p, float pval[], int ndim, float(*funk)(float *, int ndim), float ftol, int &niter);
private:
float ftol;
float TINY = 1E-10;
int NMAX = 5000;
std::ofstream fout;
};
In the declaration of member function run(), I did as:
float(*funk)(float *p, int dim);
funk = &(this->objfun1); // I define the function pointer here
amoeba(p, pval, ndim, funk, ftol, niter);
And I had the compiler errer:
error C2276: '&': illegal operation on bound member function expression
How can I refer a member function in another member function? Thank you very much!