class ShapeFactory { protected: typedef Shape *(*CreateObjectFunc)(); public: bool Register(int shape, CreateObjectFunc create_object) { if (m_object_creator.find(shape) != m_object_creator.end()) return false; m_object_creator[shape] = create_object; return true; } bool Unregister(int shape) { return (m_object_creator.erase(shape) == 1); } Shape *Create(int shape) { std::map::iterator iter = m_object_creator.find(shape); if (iter == m_object_creator.end()) return NULL; return ((*iter).second)(); } protected: std::map m_object_creator; };