Let's say I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:
I want to take that string and make it the variable name of that class type. It woule be implemented along the lines of:
When the function is called, I should get the variable:Code:string str; //read/process string here, get: str = "mustard"; createName(str); //pass string to creator function
Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.
My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question. I would greatly appreciate anyone's help.
(P.S. A bonus question for the daring: if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)