Question

Right now, the way my scene manager works is with an enum and a switch case.

I have a method that a scene can call called changeScene(MENU_SCENE) and so on.

In the scene manager itself, I have a switch case that says, case MENU_SCENE: return new MenuScene().

This means each time I add a new scene I must add it to the switch case.

Is there a batter way to do this without a switch case? Ideally I'd like something where given a string, returns a BaseScene*, but the way I can think of it would still involve a switch case (or nested ifs since strings in cases are not permitted).

Thanks

Was it helpful?

Solution

Seems like you want a map where the string is the key. The value depends on what's in your switch statement now. It could be as simple as the next string, or it could be a pointer to a function to call if you need special code for each case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top