Dear Friends at Epic,
I have tried very much to do this on my own since it does seem like just a c++ question.
But I rather stumped at the moment.
I am trying to make an array of function pointers, because I have a very large number of virtual functions I will be having each character implement. The virtual functions are basically a series of AI actions.
A function pointer array would be lovely!
#.h
typedef void (AEvolver::*EvolverFunctionPtr)(void);
EvolverFunctionPtr BehaviorFunctions[BEHAVIORS_MAX];
virtual void InitBehaviors();
virtual void PlayBehavior_Idle_LookLeftToRight();
virtual void PlayBehavior_Idle_LookFullCircle();
virtual void PlayBehavior_Idle_ScanUpDown();
#.cpp
void AEvolver::InitBehaviors()
{
BehaviorFunctions[0] = &AEvolver::PlayBehavior_Idle_LookLeftToRight;
( * (BehaviorFunctions[0]))();
}
void AEvolver::PlayBehavior_Idle_LookLeftToRight(){}
void AEvolver::PlayBehavior_Idle_LookFullCircle(){}
void AEvolver::PlayBehavior_Idle_ScanUpDown() {}
#Compile Error
1>E:\RocketVictory\VictoryGame\Source\VictoryGame\Private\Characters\Evolver.cpp(106): error C2171: '*' : illegal on operands of type 'AEvolver::EvolverFunctionPtr'
1>E:\RocketVictory\VictoryGame\Source\VictoryGame\Private\Characters\Evolver.cpp(106): error C2064: term does not evaluate to a function taking 0 arguments
#What Compiles
BehaviorFunctions[0] = &AEvolver::PlayBehavior_Idle_LookLeftToRight;
#What Doesnt
( * (BehaviorFunctions[0]))();
I’m confused as to why I can get this to compile
BehaviorFunctions[0] = &AEvolver::PlayBehavior_Idle_LookLeftToRight;
but I cannot find a way to deference and use the function pointer.
#Background
Originally I was trying to do this and was getting the compile error that there was an illegal use of & with a bound function, so I changed my typedef to this:
typedef void (AEvolver::*EvolverFunctionPtr)(void);
from this
typedef void (EvolverFunctionPtr)(void);
#Thanks for the Help
Thanks for any help with this!
Rama