I have this map
where the keys are of type MyType
and the values are maps of types <std::string, std::string>
. I need to access the values. Here's my code:
MyClass::MyClass(std::string aDefaultKey, std::map<MyType,std::map<std::string,std::string>> aTypeKVMap):
fDefaultKey(aDefaultKey)
{
std::map<std::string, std::string> fKVPairMap;
std::map<MyType,std::string> fTypeKeyMap;
for (std::map<MyType,std::map<std::string, std::string>>::iterator type_it = aTypeKVMap.begin();
type_it != aTypeKVMap.end(); type_it++)
{
std::map<std::string,std::string> kvPairs = aTypeKVMap[(*type_it).second];
fKVPairMap.insert(kvPairs.begin(),kvPairs.end());
MyType type = aTypeKVMap[(*type_it).first];
for (std::map<std::string,std::string>::iterator kv_it=kvPairs.begin(); kv_it != kvPairs.end(); kv_it++)
{
fTypeKeyMap[type] = kvPairs[(*kv_it).first];
}
}
}
When compiling, it throws two errors:
no viable overloaded operator[] for type 'std::map >' std::map kvPairs = aTypeKVMap[(*type_it).second];
And
no viable conversion from 'mapped_type' (aka 'std::__1::map, std::__1::basic_string, std::__1::less >, std::__1::allocator, std::__1::basic_string > > >') to 'MyType' MyType type = aTypeKVMap[(*type_it).first]; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How do I fix this?
Aucun commentaire:
Enregistrer un commentaire