Reputation: 135
I have a map of maps as follows:
std::map<char,std::map<short,char>> my_maps;
and I need to return a refrence to one of the maps corresponding to an specified key from a function. I do not know how I should do this ,here is my code:
bool GetMap(char key,std::unique_ptr<std::map<short,char>> my_map){
auto m=my_maps.find(key);
if(m!=my_maps.end()){
my_map=m->second;
// I have also tried this: my_map=my_maps[_commandcode];
return(true);
}
return (false);
}
Upvotes: 0
Views: 703
Reputation: 45410
This is what I will do instead:
std::map<short,char>& GetMap(char key, std::map<char,std::map<short,char>> &my_maps)
{
auto m = my_maps.find(key);
if (m != my_maps.end())
{
return m->second;
}
throw std::exception("not found");
}
Upvotes: 4