The example below uses a function pointer to a member function of the class Blah. The syntax of the function pointer is clear to me. However when calling I had to put brackets around this->*funcPtr and I am not sure why this is required. I guess it is related to the way how C++ evaluates the expression. The compiler used is VS 2008.
#include <iostream>
using namespace std;
struct Blah {
void myMethod(int i, int k) {
cout << "Hi from myMethod. Arguments: " << i << " " << k << endl;
}
typedef void (Blah::*blahFuncPtr)(int, int);
void travelSomething(blahFuncPtr funcPtr) {
(this->*funcPtr)(1, 2);
// w/o the brackets I get C2064 in VS 2008
// this->*funcPtr(1, 2);
}
};
int main() {
Blah blah;
blah.travelSomething(&Blah::myMethod);
cin.get();
return 0;
}