Hello all! I have been experimenting with function pointers, and have run into a problem. I was planning on using them as handlers for a button class. The guide I was using (http://www.newty.de/fpt/index.html) explains how to create pointers to member functions, but not pointers to member functions of pointer class (pclass->mfunction). Here is the relevant code:
Typedef for function pointer to pointer class typedefvoid (*Game::*pVoidPointer)();
"pointers to member functions of pointer class" is not a concept: raw pointer types do not have member functions. Classes do. A member function of a class to which you hold a pointer is no different from a member function of that class in any other context.
typedefvoid (*Game::*pVoidPointer)();
This pVoidPointer is a pointer to a data member of class Game, and that data member is a pointer to a non-member function that takes no args and returns void:
#include <iostream>
void fun() { std::cout << "called\n"; }
struct Game
{
void (*fptr)();
};
typedefvoid (*Game::*pVoidPointer)();
int main()
{
pVoidPointer ptr = &Game::fptr; // this is how you can initialize it
Game g;
g.fptr = fun;
(g.*ptr)(); // calls fun()
}
Thank you both, I had the arguments out of order as well as not understanding what I was trying to do. I will apply this and see how it turns out. Thanks again!