I am new to function pointers and I would like your help.
I am having a method:
int test3(int i)
{
return i;
}
Then in another method(not main) I do:
int (*pTest3)(int) = test3;
From the examples that I have read this seems ok.
However, I get a compile time error:
testFile.cpp:277:25: error: argument of type ‘int
({anonymous}::CheckingConsumer::)(int)’ does not match ‘int (*)(int)’
I do not understand what is wrong. Any help would be appreciated.
Thanks a lot.
Your
test3is a member function of astructor aclass. Class member functions have a hiddenthisparameter passed into them and so cannot be used with plain function pointers. You need to either declare the function asstaticor move it outside thestruct/class, so that it no longer has a hiddenthisparameter, or use a class method pointer instead of a function pointer: