My question is really simple. I googled a lot, but somehow I cannot figure it out. I use a C++ std::map with a std::unique_pointer like this:
std::unique_ptr<std::map<int,std::string>> my_map( new std::map<int,std::string>());
Now, I want to use the access operator [] of the map. But I always get a compiler error.
my_map[1] = "XYZ"; // error C2676
my_map->[1] = "XYZ"; // error C2059
Without the std::unique_ptr, my code would be like this, and it works. But how do I do the same via std::unique_ptr? Please help me.
std::map<int,std::string> my_map;
my_map[1] = "XYZ"; // OK!
Modern C++ is welcome and even desired.
Aucun commentaire:
Enregistrer un commentaire