title: "No match for operator=" trying to iterate through map in C++
body: <p>I'm trying to iterate through a map defined as the following:</p>
  
  <pre><code>std::map&lt; size_type, std::pair&lt;size_t, unsigned int&gt; &gt; ridx_;
  </code></pre>
  
  <p>Now I'm trying to iterate through ridx_ (which is a private member of a class) in the following friend function which overloads operator&lt;&lt;</p>
  
  <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, const SMatrix &amp;m) 
  {
    std::map&lt; size_type, std::pair&lt;size_t, unsigned int&gt; &gt;::iterator it;
  
    //The following is line 34
    for (it = m.ridx_.begin(); it !=  m.ridx_.end(); it++)
      os &lt;&lt; it-&gt;first &lt;&lt; endl;
  
    return os;
  }
  </code></pre>
  
  <p>However g++ errors out with: </p>
  
  <blockquote>
    <p>SMatrix.cpp:34: error: no match for 'operator=' in 'it =
    m->SMatrix::ridx_.std::map&lt;_Key, _Tp, _Compare, _Alloc>::begin with
    _Key = unsigned int, _Tp = std::pair,
    _Compare = std::less, _Alloc =
    std::allocator > >' /usr/include/c++/4.3/bits/stl_tree.h:152: note:
    candidates are: std::_Rb_tree_iterator > >&amp;
    std::_Rb_tree_iterator > >::operator=(const
    std::_Rb_tree_iterator > >&amp;) make: <em>*</em> [myTest] Error 1</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>