I am trying to build a class (Player) that contains a few functions, and a function pointer that points to one of those functions. I wish to call that function from another function by way of the function pointer.
I declare the function pointer like so in Player.h:
void (Player::*strat)(int);
I assign it like so in a another function in Player.cpp:
strat = &Player::tittat;
I then attempt to call the function like so from another function in Player.cpp:
strat(i);
The above call is supposed to execute, in this example, the function tittat(i). Instead, I get this stupid error:
"error C2064: term does not evaluate to a function taking 1 arguments"
I have tried everything I can think of to resolve this issue. How do I fix this?
It sounds like each of these functions belongs in a class of its own, all subclassed from the same abstract base class. The Player would then have an object of this type as a member. It's easier to work with functions as objects this way.
Thanks, that strategy patter will definitely come in handy! Gosh, this just goes to show what a C++ n00b I am: Where would one initialize the object p? Would I need to do that in the class where I implement the Player class, or could I do it in the Player class itself? Keep in mind, I wish to be able to do this: