I am new to using smart pointers and have only used unique_ptr
so far. I am creating a game and I am using a vector
of unique_ptr
to store my game states.
Here is my vector code:
std::vector<std::unique_ptr<GameState>> gameStates;
Here is my question. Are the following functions going to work to control my vector:
void GameStateManager::popGameState(){
if (getCurrentGameState() != nullptr)
gameStates.pop_back();
}
void GameStateManager::pushGameState(GameState *gameState){
gameStates.push_back(std::unique_ptr<GameState>(gameState));
}
GameState *GameStateManager::getCurrentGameState(){
return gameStates.back().get();
}
My worries where that using raw pointers as arguments and to return the current game state would eliminate the point of using smart pointers. Is this a good way to do this?