1

I have a map of map

std::map< int, std::map<string, double> > myMap;
std::map< int, std::map<string, double> >::iterator itr;

Iterating it with:

   itr = myMap.find(nodeI);
   if (itr == myMap.end())
   {
        exit(1) ;
   }

results in the error:

      error: no match for âoperator=â in 
      âitr = ((const PushList*)this)->PushList::myMap.std::map&lt:_Key, _Tp, _Compare,    _Alloc>::find 

  [with _Key = int, _Tp = std::map&lt:std::basic_string&lt:char, std::char_traits&lt:char>,    
  std::allocator&lt:char> >, double, std::less&lt:std::basic_string&lt:char,   
  std::char_traits&lt:char>,  
  std::allocator&lt:char> > >, std::allocator&lt:std::pair&lt:const std::basic_string&lt:char, 
  std::char_traits&lt:char>, std::allocator&lt:char> >, double> > >, _Compare =  
  std::less&lt:int>, _Alloc = 
  std::allocator&lt:std::pair&lt:const int, std::map&lt:std::basic_string&lt:char, 
  std::char_traits&lt:char>, 
  std::allocator&lt:char> >, double, std::less&lt:std::basic_string&lt:char, 
  std::char_traits&lt:char>, 
  std::allocator&lt:char> > >, std::allocator&lt:std::pair&lt:const std::basic_string&lt:char, 
  std::char_traits&lt:char>, std::allocator&lt:char> >, double> > > > >](((const 
   int&)((const int*)((int*)nodeI))))â

How can I iterate the map of map?

outis
  • 75,655
  • 22
  • 151
  • 221
dtustudy68
  • 325
  • 1
  • 4
  • 13
  • Where are the a-circumflex ('â') characters coming from? Are they in the original error message, or are they due to character translation issues? – outis Oct 13 '11 at 05:27
  • 2
    The sample code (when minimal code is added so it compiles) doesn't produce the error. Please update your question with a [minimal test caste](http://sscce.org/). – outis Oct 13 '11 at 05:42
  • Do you do anything with the iterator other than check it against end()? You could use the count() method: `if (myMap.count(nodeI) == 0) { exit(1); }` – MtnViewJohn Oct 13 '11 at 06:03

1 Answers1

4

From the error you posted it can be seen that you are doing this from within a class member const function. Is there any chance that myMap happens to be a member of that class? If so, what you want is to use const_iterator instead. You should do it anyways, since you are not expecting to modify the contents of the iterated elements.

K-ballo
  • 80,396
  • 20
  • 159
  • 169