title: boost::bind and class member function
body: <p>Consider following example.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  
  #include &lt;boost/bind.hpp&gt;
  
  void
  func(int e, int x) {
      std::cerr &lt;&lt; "x is " &lt;&lt; x &lt;&lt; std::endl;
      std::cerr &lt;&lt; "e is " &lt;&lt; e &lt;&lt; std::endl;
  }
  
  struct foo {
      std::vector&lt;int&gt; v;
  
      void calc(int x) {
          std::for_each(v.begin(), v.end(),
              boost::bind(func, _1, x));
      }
  
      void func2(int e, int x) {
          std::cerr &lt;&lt; "x is " &lt;&lt; x &lt;&lt; std::endl;
          std::cerr &lt;&lt; "e is " &lt;&lt; e &lt;&lt; std::endl;
      }
  
  };
  
  int
  main()
  {
      foo f;
  
      f.v.push_back(1);
      f.v.push_back(2);
      f.v.push_back(3);
      f.v.push_back(4);
  
      f.calc(1);
  
      return 0;
  }
  </code></pre>
  
  <p>All works fine if I use <code>func()</code> function. But in real life application I have to use class member function, i.e. <code>foo::func2()</code> in this example. How can I do this with boost::bind ?</p>