In C++ I’m trying to make a simple state machine for a game, based on classes.
stateMan.setState<mainMenuState>();
I have a class with the declaration as:
class stateManager
{
...
template <class T>
void setState(void);
}
And the test code as:
template <class T>
void stateManager::setState<T>(void)
{
T* blah = new T;
delete blah;
}
And obviously this doesn’t work since function template partial specialization ‘setState<T>’ is not allowed.
Would there be a better way to do this besides doing it non-OO?
The definition of the member function template should be this:
That is, it should be simply
setStateinstead ofsetState<T>. The latter syntax is used in function template specialization. SinceTis a type parameter, the specialization would be considered as function partial template specialization which is not allowed.