문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top