I have written the following code...
PagesMap::const_iterator end = pagesMap.end();
for ( PagesMap::const_iterator it = pagesMap.begin(); it != end; ++it )
{
....
it->second = 0; // Here I get the error
//pagesMap[it->first] = 0;
}
Now at line where I have it->second = 0;, I get...
error: assignment of data-member ‘std::pair::second’ in read-only structure
If I use the commented code below that line, it works, but It's my guess that it is not efficient. Is there an efficient way to achieve this?
It's because you are using a const_iterator; try changing to an iterator instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With