title: no matching function for call to for_each
body: <p>here is the code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;string&gt;
  #include &lt;map&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  map&lt;string, int&gt; g_map;
  void read_item(const pair&lt;string, int&gt;&amp; p) {
     g_map[p.first] += p.second;
  }
  
  void myprint(std::pair&lt;const string, int&gt; ci) {
     cout &lt;&lt; "first : " &lt;&lt; ci.first &lt;&lt; "seconde : " &lt;&lt; ci.second &lt;&lt; endl;
  }
  
  void myprint(int ci) {
     cout &lt;&lt; ci &lt;&lt; endl;
  }
  
  int main()
  {
      string a = string("nail");
      string b = string("hammer");
      read_item(make_pair(a, 100));
      read_item(make_pair(b, 2));
      read_item(make_pair(b, 10));
      read_item(make_pair(a, 200));
  
      std::for_each(g_map.begin(), g_map.end(), myprint); // can't find the matching function here
      vector&lt;int&gt; vec;
      vec.push_back(3);
      vec.push_back(3);
      std::for_each(vec.begin(), vec.end(), myprint);  // and here
      return 0;
  }
  </code></pre>
  
  <p>I overloaded the function <code>myprint</code>, I think it should be working, but it doesn't. when I change the first <code>myprint</code> to <code>myprint1</code> and the second to <code>myprint2</code>, it works. any body can help? the compile error is:</p>
  
  <pre><code>funcTemOverload.cpp: In function 'int main()':
  funcTemOverload.cpp:29:54: error: no matching function for call to 'for_each(std::map&lt;std::basic_string&lt;char&gt;, int&gt;::iterator, std::map&lt;std::basic_string&lt;char&gt;, int&gt;::iterator, &lt;unresolved overloaded function type&gt;)'
  funcTemOverload.cpp:29:54: note: candidate is:
  In file included from d:\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include/c++/algorithm:63:0,
           from funcTemOverload.cpp:2:
  d:\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include/c++/bits/stl_algo.h:4436:5: note: template&lt;class _IIter, class _Funct&gt; _Funct std::for_each(_IIter, _IIter, _Funct)
  d:\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include/c++/bits/stl_algo.h:4436:5: note:   template argument deduction/substitution failed:
  funcTemOverload.cpp:29:54: note:   couldn't deduce template parameter '_Funct'
  funcTemOverload.cpp:35:50: error: no matching function for call to 'for_each(std::vector&lt;int&gt;::iterator, std::vector&lt;int&gt;::iterator, &lt;unresolved overloaded function type&gt;)'
  funcTemOverload.cpp:35:50: note: candidate is:
  In file included from d:\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include/c++/algorithm:63:0,
           from funcTemOverload.cpp:2:
  d:\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include/c++/bits/stl_algo.h:4436:5: note: template&lt;class _IIter, class _Funct&gt; _Funct std::for_each(_IIter, _IIter, _Funct)
  d:\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include/c++/bits/stl_algo.h:4436:5: note:   template argument deduction/substitution failed:
  funcTemOverload.cpp:35:50: note:   couldn't deduce template parameter '_Funct'
  </code></pre>