The second option. ie the type already exists, the object will be created at run time.
What i really want to do whenever the user enters a name for a folder(say that name is Engineering) as a string that name is taken and used to create an object of type FOLDER and the name of the object is called "Engineering".
@xismn
It does sound that far-fetched. The idea is that i want the program to create a new object of a particular type that has a name that is specified by the user. The end result will be the number of objects created is determined by the number of names given by the user but all of the same type
Not that far-fetched. Just map a name to a specific object and you're good to go. Whenever you're presented with the name, look up the associated object.
Variable names cease to exist during the compilation and linking process. They're identifiers used by the compiler to know which of all the many objects you mean, but the names are discarded after that because there's really no use for them. If you're simply trying to keep track of which object was created when, or let the user label the objects, then you can either have the objects hold their own label (as in JLB's code above) or you can simply have a map (i.e. a look up table) that keeps track of what each object has been named (as Cire suggests).
Are you asking out of curiosity (in which case this is an interesting and educational diversion), or is there some problem you're trying to solve?
explicit folder( std::string name ) : name_(name) {}
Initialise the non-static member _name with the string name. : name_(name) is the mem-initializer-list, name_(name) is the lone mem-initializer http://en.cppreference.com/w/cpp/language/initializer_list
Perhaps the use of the identifier name in more than one context (more than one scope) is the source of this doubt;
this may be a bit easier to understand:
There is a problem that i am actually trying to solve that lead me down this path which also made me curious as to how the compilation and linking process is done, based on what you explained.
I have found a solution based on what was suggested .
I am just writing a helper program for myself that organizes the files on my computer.
It will read files in a specified directory and based on that name decide on where the files should be moved to. Where the files should be moved to are the folders that are specified by the user of the program, these are the destination folders. These destination folders have string parameters(specified by user) that will be compared to the name of file to determine where the file should be moved.
That solution seems to be the simplest. However like cire stated you could also use a map
(ie http://www.cplusplus.com/reference/map/map/) to pair your folders with an associated key (the key would be the name) or you could try hashing where the hashing key is a string representing the name of the directory