I'm working with a standard container and it keeps getting a compile error about discarded const qualifiers even though I'm not making any changes to it.
Code:
void foo(const map<string, pair<int, int> >& m)
{
string search_string = "bar";
int a = m[search_string].first; // !Error about "passing const map<yadayada> as
//'this' argument of "yada yada" discards qualifiers"
int b = m[seach_string].second;
}
// the second yada yada in this case is
//'std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key =
//std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::pair<unsigned int,
//unsigned int>, _Compare = std::less<std::basic_string<char, std::char_traits<char>,
//std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char,
//std::char_traits<char>, std::allocator<char> >, std::pair<unsigned int, unsigned int> > >]’
Do I have to use the dreaded const_cast?