You're looking for Game States
or a State Machine (google's your friend).
In pseudo-not-working code, it looks like :
class State
{
public:
virtual void handleEvents() = 0; // handle player, world events
virtual void update() = 0; // do the logic
virtual void render() = 0; // draws on screen
private:
sf::Window& mWindow;
};
// Inherit from State to do some MenuState, GameState, GameOverState and stuff
class Game
{
public:
void changeState(State* state);
void play()
{
mState = new MenuState(this);
while(mWindow.isOpen())
{
mState->handleEvents();
mState->update();
mState->render();
}
}
private:
sf::RenderWindow mWindow;
State* mState;
};
This would be a *very* simple implementation of States. You will probably need to give states more data (a context about your app), make pointers be smart, etc.
Have a look at the book SFML "Game Programming", there's such a thing implemented. Sources are available on GitHub (you'll find the link to the repo somewhere on the forum).