Original Post
I'm trying to implement an object factory so that I can instantiate a object by just having the name of a class. I'm using a std::map to store a function pointer for creating a derived instance of a base class with the name as a key. and the implementation of SceneManager::RegisterEntity then somewhere in the code I call this: and it gives me a seg fault. The backtrace of gdb tells me that the function being called is unknown. Here's the code for SceneManager::CreateEntity I know there's no error checking here, I'll be putting that in later. When I step through this, it's not finding the function registered in the map. Any ideas what's happening here? -bodiddlie
CBaseEntity* CreateTexturedSphere()
{
return new TexturedSphere;
}
const bool registered = SceneManager::Instance()->RegisterEntity("textured_sphere", CreateTexturedSphere);
bool SceneManager::RegisterEntity(char* name, CreateEntityCallback CreateFn)
{
return mCallbacks.insert(std::pair<char*, CreateEntityCallback>(name, CreateFn)).second;
}
CBaseEntity* mPlanet;
mPlanet = SceneManager::Instance()->CreateEntity("textured_sphere");
CBaseEntity* SceneManager::CreateEntity(char* name)
{
CallbackMap::iterator it = mCallbacks.find(name);
return (it->second)();
}