Hello,
I wonder if it was at all possible to use the c++11 feature of variadic template to act as an optional paramters, aside from some fixed ones? I'm trying to abstract the process of creating a new game state for my state system. All of my main game states (main menu, editor, game) have four fixed objects they need, plus some optional parameters:
class BaseState :
public IState
{
public:
BaseState(gfx::IGfx3D& gfx3D, ecs::EntityManager& entityManager, ecs::SystemManager& systemManager, ecs::MessageManager& messageManager);
~BaseState(void);
protected:
template<typename S, typename... Args>
void NewState(Args&&... args);
gfx::IGfx3D* m_pGfx3D;
ecs::EntityManager* m_pEntities;
ecs::SystemManager* m_pSystems;
ecs::MessageManager* m_pMessages;
IState* m_pCurrentState;
};
template<typename S, typename... Args>
void BaseState::NewState(Args&&... args)
{
m_pCurrentState = new S(*m_pGfx3D, *m_pEntities, *m_pSystems, *m_pMessages, args...);
}
Not talking about how I could probably pack the four variables into one to make the constructor less ugly... calling it that way:
void MainMenuState::OnNewGame(void)
{
NewState<GameState>();
}
results in the following error:
1>C:\Acclimate Engine\Repo\Editor\Core/BaseState.h(44): error C2661: 'GameState::GameState' : no overloaded function takes 5 arguments
1> MainMenuState.cpp(26) : see reference to function template instantiation 'void acl::core::BaseState::NewState<GameState,>(void)' being compiled
Obviously, it still takes the variadic template as a fifth parameter, even though normally varidic templates "extinct" if I don't submit any in the call. Does somebody know how to solve that?