Hi all!
This is a C++ question, however i am not sure if it really somehow deals with type information.
The problem is that i want to have a "command file", where i say write the name of the objects to be created. For example:
if we have a file:
command.myf
tree
spaceship
house
then, when i read this file in my program, i need to create:
CMyTree object for "tree", CMySpaceship object for "spaceship" and a CMyHouse object for "house". (It may be that, say, CMyTree and CSpaceship are derived from the same base class but it really doesn''t matter)
Well, the one solution is to use a switch statement in my program, or a series of if-else connections. But it is cumbersome, and not that effective...
I beleive, this can be done in some way, using a "map" that contains the object
ID s (?) and corresponding strings in my file... Then, when i read a statement from the file, i scan the map and retreive the corresponding object ID... but after that i need to create an object of that type... say:
CMyBaseClass* pNewObj = new RETRIEVED_TYPE;
My question is in how to determine "RETRIEVED_TYPE" (from "typeid"?) and what would be the correct syntax for the upper statement?
Thank you very much for any help, in advance.
Links will also be very appreciated!
C++ RULEZ!!!