Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STL map (read only)

Status
Not open for further replies.

hectorDUQUE

Programmer
Jan 29, 2007
23
hi guys,

do you know what this means:

Code:
error: increment of data-member 'std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::second' in read-only structure

i don't understand how a map structure can be a read only structure. The code is:

Code:
          typedef std::map<string, int> map_groups2counters_type;

	  map_groups2counters_type::const_iterator groups2countersIterator;
	  groups2countersIterator = groups2counters.find( groups2counters_mapKey_ch );

	  if ( groups2countersIterator == groups2counters.end() ){

	    //does not exist, so initializa the counter
	    groups2counters.insert(std::make_pair(groups2counters_mapKey_ch, 1));

	  } else{

	    //exists, so increase the counter
	    groups2countersIterator->second++;

	  }//if

thanks in advance,

hector
 
the error was reported in the line

Code:
         groups2countersIterator->second++;
 
Perhaps this?
[tt]map_groups2counters_type::[red]const_[/red]iterator[/tt]
shouldn't be const if you intend to modify things.



--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
yes, it is!

but, i don´ t understantd why. It is not the iterator it self which i ám trying to modify.

????

thanks ....

hector
 
A const_iterator means the thing the iterator is pointing to is const, not the iterator (otherwise, how could you iterate in the first place?)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top