What I want to do is to take the string and make it the name of the object. For example if I had a program where the user inputs a customer's name and I then need to make a class object that is named the same name the user input. In the top example, instead of creating m or j as an object I need to create the text in the string as an object.
The customer example was just a simple way to show what I'm talking about, but what I'm working on is a program that takes in a bunch of files and I want to store info from each file into it's own class object, so that later on I can display it in my program. When a new file is input, the program adds the names of them to a listbox. When I select something in the listbox I want it to look in the class object that was made using name of the file in order to load the details of the specific file.
struct info
{
explicit info( std::string file_name )
{
// open file
// read and store into member variables
}
// ...
static std::map< std::string, info > look_up_table ;
static info info_by_name( std::string file_name )
{
auto iter = look_up_table.find(file_name) ;
if( iter == look_up_table.end() ) // not found; info was not loaded
iter = look_up_table.insert( { file_name, info(file_name) } ).first ; // create info, add to look up table
return iter->second ; // return info
}
};