私は現在、この問題が発生した場所で何かをプログラミングしています:
私はScene
クラスとクラスを持っていますMainScene
:
class Scene{
Scene();
}
class MainScene : public Scene{
MainScene();
}
そして、私がやりたいことは、次のようなシーンのリストを追跡することです:
std::map<std::string, Scene*> scenes;
そして、次のようにシーンを追加します。
MainScene* mainscene; //I do not make it a new because i want my scenemanager to handle that
scenes.emplace("mainscene", mainscene); // add it to the list
そして、私は次のような関数を持っています:
template <class T>
void SceneManager::recreateScene(T* &scene)
{
scene = new T();
}
関数を使用したい場合はloadscene
、リストからシーンを取得して現在のシーンを削除し、関数を使用して新しいシーンを作成できますrecreateScene
。しかし、地図は私に与えますScene
。したがって、使用すると、の代わりにrecreateScene
のコンストラクターが呼び出されます。しかし、リスト内のシーンが であることを知る必要があるため、ではなく が作成されます。Scene()
MainScene()
MainScene
new MainScene()
new Scene()