Lets say, for example, I want to make a "get()" function for a map outside of the map class (for some reason). The implementation says that std::map has members map::key_type and map::mapped_type. However, I can't seem to access them.
1 2 3 4 5 6 7 8
std::map<std::string,std::string> tbl;
tbl.mapped_value get(tbl.key_value s) {
if(tbl.find(s) == tbl.end()) {
throw std::runtime_error{"key s does not exist."};
}
return tbl[s];
}
The implementation says that std::map has members map::key_type and map::mapped_type.
TinyTertle wrote:
tbl.mapped_value get(tbl.key_value s) {
As you said a few lines earlier, the types are named "key_type" and "value_type", not "key_value" or "mapped_value". And member types are accessed using the :: operator on the type: