I've been working on a Finite State Machine in C++, and it's been a while since I last worked in C++ (Have been using C and Java for the past 2 years or so). Obviously this leads to some issues that might sometimes be trivial to solve, but it's all a bit rusty for me.
So here's a problem I came across and can't manage to solve.
The problem relates to 4 files, StateMachine.h, StateMachine.cpp, SpawnEntity.h and SpawnEntity.cpp.
In StateMachine.h, I define a function called changeState, with templates to make it reusable. This looks as follows:
StateMachine.h
//Forward declare classesclass State<class character_type>;template <class character_type>class StateManager{public: StateMachine(){} void changeState(State<character_type>*); ~StateMachine(){}};
StateMachine.cpp
#include "main.h" //holds all header filestemplate <class character_type>void StateManager<character_type>::changeState(State<character_type>* newState){ //Do something }
SpawnEntity.h
//Forward Declareclass TestType;class SpawnEntity : public State<TestType>{public: void execute(TestType*);};
SpawnEntity.cpp
#include "main.h" //Same main as beforevoid SpawnEntity::execute(TestType* owner){ FSM->changeState(State_NextState); //This is where the error occurs}
The State Class is an abstract class which is implemented by classes such as SpawnEntity and NextState, to ensure consistent methods. TestType is derived from a class called Entity, specifying a few methods which aren't really relevant to this problem.
The error is as follows:
SpawnEntity.cpp:(.text+0xe6): undefined reference to `StateManager<TestType>::changeState(State<TestType>*)'
Thanks in advance for your help.