title: what is wrong using for_each/mem_fun
body: <p>I am using C++98.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;functional&gt;
  
  struct Foo {};
  
  void
  add_each(std::vector&lt;std::vector&lt;Foo*&gt; &gt; &amp;vv, const Foo *f)
  {
      for_each(vv.begin(), vv.end(), std::bind2nd(std::mem_fun(&amp;std::vector&lt;Foo*&gt;::push_back), f));
  }
  </code></pre>
  
  <p>Basically I like to add an element to the end of every vector.</p>
  
  <p>G++ complains the line of for_each.</p>
  
  <pre><code>In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/algorithm:62,
                   from 1.c:2:
  /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h: In function â€˜_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator&lt;std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;*, std::vector&lt;std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;, std::allocator&lt;std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt; &gt; &gt; &gt;, _Funct = std::binder2nd&lt;std::mem_fun1_t&lt;void, std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;, Foo* const&amp;&gt; &gt;]â€™:
  1.c:10:   instantiated from here
  /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:4200: error: no match for call to â€˜(std::binder2nd&lt;std::mem_fun1_t&lt;void, std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;, Foo* const&amp;&gt; &gt;) (std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;&amp;)â€™
  /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/backward/binders.h:146: note: candidates are: typename _Operation::result_type std::binder2nd&lt;_Operation&gt;::operator()(const typename _Operation::first_argument_type&amp;) const [with _Operation = std::mem_fun1_t&lt;void, std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;, Foo* const&amp;&gt;]
  /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/backward/binders.h:152: note:                 typename _Operation::result_type std::binder2nd&lt;_Operation&gt;::operator()(typename _Operation::first_argument_type&amp;) const [with _Operation = std::mem_fun1_t&lt;void, std::vector&lt;Foo*, std::allocator&lt;Foo*&gt; &gt;, Foo* const&amp;&gt;]
  </code></pre>
  
  <p>Do you see what is wrong?</p>