Is there a way to pass member function as a parameter to a global function ? I found this but it doesn't really solve my problem.
Lets say that I have following global functions:
double Function(double (*fEval)(double F1, double F2),double min, double max,int numArgs,...);
bool Function2(double (*fEval1)(double F1, double F2),double (*fEval2)(double F1, double F2),double xmin, double xmax, double ymin, double ymax,double &ax, double &ay,int numArgs,...);
and one of my member functions calls Function2 as
Function2(&F1, &F2, 0, m_m1, 0, m_m2, &m_n1, &m_n2,0);
Where F1 and F2 are member functions and Function2 calls somewhere Function1 but at the moment my problem is with Function2 and how to declare it correctly.
Okay now I've managed to change my function declaration to
bool Function2(double (CLASS::*)(double F1, double F2),double (CLASS::*)(double F1, double F2),double xmin, double xmax, double ymin, double ymax,double *ax, double *ay,int numArgs,...)
And I have probably only one problem which occurs when I'm trying to call the functions fEval1 and fEval2 which have been replaced with CLASS::* so how I can call the first and second member functions within this function ?
Member function pointers are different to ordinary function pointers - you need to specify their class as part of the type. Also, when calling them, you need to specify an object for which the member function is called.
Your error message shows that the type of member-function which you're passing is in fact double (CLASS::*)(double, double) - this isn't compatible with the ordinary function pointer type in the signature
Have a look at the C++ FAQ here for a bit more information on how to use member function pointers:
http://www.parashift.com/c++-faq-lite/pointers-to-members.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With