>> Oh, and....how are pointers to functions useful, too?
I think he's talking about function pointers, dougdbug
Function pointers are nice if you want to avoid a bunch of branching statements, i.e.:
You can replace this with:
state = RUN_STATE_1;
In this example you'll improve efficiency too, because you'll have eliminated a branching statement. Of course I rarely do something like this, but it's something you can do. Another example is callback routines - you might want to specify, when something happens you want a certain function to be called. Well, you'd just set a function pointer to the function you want, and the function you specified would be called when that something happens. This is especially useful for applications like scripting engines:
void (*stateFunction)(void); //declared somewhere, modified by various functions
stateFunction = &doFunction1;
stateFunction = &doFunction2;
Something along those lines.
typedef void (*funcPtr)();
map<string, funcPtr> funcMap;
funcMap["attack"] = &attack;
funcMap["jump"] = &jump;
map<string, funcPtr>::iterator it = funcMap.find(cmd);
if(it != funcMap.end())