I am trying to use a function pointer, but the 3 lines below just do not seem to want to cooperate…
I’m getting error code C3867.
Can you see what I’m doing wrong?
In .h file
void MyFunc(int, FILEINFO*(*)(FILEINFO*), FILEINFO*, int);
The definition in the .cpp file
void MyFunc(int number, FILEINFO*(*GetFiles)(FILEINFO*), FILEINFO* args, int type);
Then here is where I’m actually calling the function
MyFuncClass->MyFunc(GetNumber(), &BigClass::PassThis, GetArgs(), TheType);
Any problems jump out?
You cannot pass a non-static member function of a class as an
ordinary function pointer, since a member function implicitly uses the
this-pointer. A solution for this is to define a static member function that takes a pointer
to the class as it’s first argument and wraps the call to
BigClass::PassThisand pass a pointer to that member function instead. Please seeThe Function Pointer Tutorials for more information.
A better solution might be to look into using functors instead.