   Generic Factory, good/bad?
  I'm sitting at work, and had an idea pop in my brain.  I'm sure that someone has thought/done this before.  I want to know if this would be a good approach to creating a factory or not.I was thinking I could make the factory generic(using templates), and contain a registry map.  Something like thistemplate <class CreatedType, typename ID = std::string>class GenericFactory{   typedef CratedType* (*CreateFunction)();   typedef std::map<ID, CreateFunction> FuncRegistry;   FuncRegistry m_registry;   GenericFactory()   GenericFactory(const GenericFactory&);   GenericFactory &operator=(const GenericFactory&);public:    static GenericFactory& instance();   void RegCreateFunc(const ID&, CreateFunction);   CreatedType* Create(const ID &ClassId) const;};Then to handle the abstract types a function like this could be writtentemplate <class BaseType, class AbstractType, ID = std::string>class RegToFactory{ static *BaseType CreateInstance() { return (*BaseType)(new AbstractType); } RegToFactory(ID &classId) { GenericFactory<BaseType>::instance().RegCreateFunc(classId, CreateInstance); }};The singleton design is a bit sloppy, but this is all off the top of my head, and I don't even know if it will work right because I'm at work not in front of a compiler...Is this a good way of going about a factory?  Seems to me it would be an easier way to go about things then creating a derived factory for each type.
  Sure; I do something like this for resource management now, though it often still needs to be derived out to handle some of the peculiarities for each type or to provide error/input/event handling.Still, quite useful for consolidating common code which differs merely on type.   