Question

I am trying to initialize a map of map but I am unsure what mistake I am doing. Below is the sample code.

static  std::map<std::string, std::map<std::string,std::string>>  _ScalingMapVolume ={
    {"AA",{"busy_timeout","test"}},
    {"BB",{"cache_size","10000"}}
};

The error I am getting is;

error: no match for call to ‘(std::_Select1st<std::pair<const std::basic_string<char>, std::basic_string<char> > >) (const char&)’

Was it helpful?

Solution

{"busy_timeout","test"} is not the value of a map, but a pair. You need {{"busy_timeout","test"}}.

Your code should look like this:

static  std::map<std::string, std::map<std::string, std::string>>  _ScalingMapVolume = {
   {"AA", {{"busy_timeout", "test"}}},
   {"BB", {{"cache_size", "10000"}}}
};

OTHER TIPS

init = {{"AA", {"busy_timeout", "test"}}, ...}

You are missing one set of braces, since the value_type of the map is std::pair<const std::string, std::map<std::string, std::string>>. The value_type of the mapped_type is std::pair<const std::string, std::string>. So you need to use it that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top