Templates With Inheritance 0.o...
Posted: Tue May 04, 2010 10:35 pm
So to give a little back drop on my problem, I'm currently (attempting) to make a SHMUP and I've just made a State Machine and base State class (each templates for the type of object that it's for... States are singletons... Most of this is chunks I got from the book Programming Game AI By Example).
So I have a Singleton template, just the standard Meyer's implementation.
I have the State Machine template which holds states of it's own template type, and lastly the State template.
So in my base enemy class I have the State Machine declared as:
Now I make a basic enemy, a Grunt, and make a state for it:
Then I initialize the state machine like:
Error... Can't convert parameter 1 from StateMachine<Grunt>* to StateMachine<entity_type>*... I just assumed that would work because inheritance established that "A Grunt IS AN Enemy". So when that failed, I initialized the StateMachine like this:
Alright, that works, but now I get an error when I try to set the state:
Another error... Can't convert parameter 1 from Grunt_Idle* to State<entity_type>*... Again, I assumed that because a Grunt is an enemy, it would work...
Here's the declaration of Grunt_Idle:
So I could probably just chain everything up to the base Enemy class, but my problem is, what if I need the state to access sub class specific data? So... I'm sure there's a way to accomplish it, Thanks in advance for any help!
So I have a Singleton template, just the standard Meyer's implementation.
I have the State Machine template which holds states of it's own template type, and lastly the State template.
So in my base enemy class I have the State Machine declared as:
Code: Select all
StateMachine<Enemy>* m_pStateMachine;
Code: Select all
class Grunt_Idle : public State<Grunt>
Code: Select all
m_pStateMachine = new StateMachine<Grunt>(this);
Code: Select all
m_pStateMachine = new Statemachine<Enemy>(this);
Code: Select all
m_pStateMachine->SetCurrentState(Singleton<Grunt_Idle>::GetInstance());
Here's the declaration of Grunt_Idle:
Code: Select all
class Grunt_Idle : public State<Grunt>