   C++ Object Manager
  Hey Everyone,I am trying to create a C++ class that is basically an object factory and manager. The object manager will have two jobs:1. Create new objects of a specified type.2. Maintain a reference to that object until there are no more references and then delete it.I want to be able to create objects by specifying the type and a list of arguments. The problem that I am having is figuring out how to represent data types without having to hard code how to create each new class that I write.void *createObject(ObjType obj, void *args);Is it possible to write a function that would be able to do something like:int[1] iArray = {34};int *integer = createObject(int, iArray);Thank you for your help!   
  Often, factories are used to return a specific derived class... For example you might have CUnit which has derived classes CSoldier, CArcher, and CCavalry. Then your function could return a CUnit pointer to any of those 3 without a problem.If you want to write a function that can return literally ANY type of class, I'm not sure if there's a good general way to do it. You could use void pointer of course, kind of hacky and not safe though. Or you could just have entirely different functions like CreateMoneky(), CreateSpaceship(), etc. *shrug*I'm still learning design patterns myself so if I said something wrong forgive me :)   ;  I had a similar problem, the way I ended up doing it was to have a general Resource Manager which would maintain a list of factories.  Factories register themselves with the resource manager as well as their 'identifier'.So something like this, in pseudo code:ResourceManager.RegisterFactory(kDogFactory, &MyDogFactory);ResourceManager.RegisterFactory(kCatFactory, &MyCatFactory);.. Later on I can do this:DogObject* pObj = (DogObject*)ResourceManager.CreateResource(kDogFactory, args);Each factory is responsible for knowing how to create the particular object, and the ResourceManager just forwards the args to the appropriate factory.Hope that helps :)Graf   