std::map<std::string, SomeClass> exampleMap;
void addToExampleMap() {
exampleMap["foo"] = SomeClass();
}
int main() {
addToExampleMap();
exampleMap["foo"].doSomething(); //error because the object does not exist
return 0;
}
Obviously this is very oversimplified, but when I run something like this, the new SomeClass object that I set "foo" to is being deleted at the end of the function since it is a local variable (at least that's what I think is happening). How would I add that empty SomeClass to exampleMap without letting it get deleted after the function exits?