title: std::bind a member function to an object pointer
body: <p>I have class with member functions:</p>
  
  <pre><code>typedef std::function&lt;bool (const std::string &amp;)&gt; InsertFunction;    
  
  bool insertSourceFile( const std::string &amp; );
  bool insertSourceDir( const std::string &amp; );
  bool insertHeaderFile( const std::string &amp; );
  bool insertHeaderDir( const std::string &amp; );
  </code></pre>
  
  <p>I'd like to have a reference to one of these <code>InsertFunction</code>s in another class, and use it to do its job (without having to make classes for each of these functions). I tried using the class constructor and <code>std::bind</code> to bind the member function's implicit first argument to a pointer of the object in question:</p>
  
  <pre><code>new ListParser( p_target-&gt;sourceDirs(), bind(&amp;Target::insertSourceFile, p_target, _1), this );
  </code></pre>
  
  <p>with</p>
  
  <pre><code>ListParser::ListParser( const stringSet &amp;dirs, const InsertFunction &amp;insert,
                          State* parent = 0 )
  :   ParserState( parent ),
      m_dirs( dirs ),
      m_insert( insert )
  {    }
  </code></pre>
  
  <p><strong>UPDATE</strong>: thanks to @lijie, the source now compiles, but when the function m_insert is called, a <code>std::exception</code>is thrown for <code>std::bad_function_call</code>. What could be wrong? Thanks! If you need more info, please ask!</p>