How to pass a member function to a function used in another member function?

Posted by Tommaso Ferrari on Stack Overflow See other posts from Stack Overflow or by Tommaso Ferrari
Published on 2013-07-01T16:09:07Z Indexed on 2013/07/01 16:21 UTC
Read the original article Hit count: 124

I found something about my problem, but I don't already understand very well. I need to do something like this:

class T{
double a;
public:
double b;
void setT(double par){
a=par;
};

double funct(double par1) {
return par1/a;
} 

void exec(){
b=extfunct(funct, 10);

}

}


double extfunct(double (*f)(double),double par2){

return f(par2)+5;

}

Operation and function are only for example, but the structure is that. The reason of this structure is that I have a precostituited class which finds the minimum of a gived function (it's extfunct in the example). So I have to use it on a function member of a class. I understood the difference between pointer to function and pointer to member function, but I don't understand how to write it. Thanks, and sorry for the poor explanation of the problem.

© Stack Overflow or respective owner

Related posts about c++

Related posts about function-pointers