I am creating an unordered_map (C++ STL). The key is of type std::string and the value will be a pointer to objects of class X. the string key is actually the name of the object itself and will be stored as an instance variable in objects of that class. Is there a way for me to insert key,value pairs in unordered_map so that it does not allocate memory for the key?
I came up with the following solution ->
class X
{
public:
const string name;
X(char * c_name) : name(c_name) {}
};
unordered_map<string, X *> x_store;
X *a = new X("some_name");
x_store.insert(make_pair(a -> name, a))
but i believe the string object will be duplicated.