title: Passing the method of an abstract class as std::function
body: <p>I have some code like this (This is just a snippet, not completely valid code):</p>
  
  <pre><code>class AbstractClass {
  public:
      AbstractClass() {}
      virtual ~AbstractClass() {}
      virtual void doA() { std::cout &lt;&lt; "doA1\n"; };
      virtual void doB() = 0;
  };
  
  class ImplClass : public AbstractClass {
  public:
      ImplClass() {}
      virtual ~ImplClass() {}
      virtual void doA() override { std::cout &lt;&lt; "doA2\n"; };
      virtual void doB() override { std::cout &lt;&lt; "doB2\n"; };
  };
  </code></pre>
  
  <p>Now i would like to store a call to a member method of the AbstractClass within a std::function like this:</p>
  
  <pre><code>int main() {
      AbstractClass* aClass = new ImplClass();
      std::function&lt;void()&gt; func = std::bind(&amp;AbstractClass::doA, *aClass)
  
      delete aClass;
      return 0;
  }
  </code></pre>
  
  <p>However this does not work, according to the compiler due to the existance of pure virtual methods within AbstractClass.</p>
  
  <p><strong>Edit:</strong> For reference the complete error</p>
  
  <pre><code>In file included from source_file.cpp:2:0:
  /usr/include/c++/5/functional: In instantiation of ‘struct std::_Bind_helper&lt;false, void (AbstractClass::*)(), AbstractClass&amp;&gt;’:
  /usr/include/c++/5/functional:1462:5:   required by substitution of ‘template&lt;class _Func, class ... _BoundArgs&gt; typename std::_Bind_helper&lt;std::__is_socketlike&lt;_Func&gt;::value, _Func, _BoundArgs ...&gt;::type std::bind(_Func&amp;&amp;, _BoundArgs&amp;&amp; ...) [with _Func = void (AbstractClass::*)(); _BoundArgs = {AbstractClass&amp;}]’
  source_file.cpp:26:72:   required from here
  /usr/include/c++/5/functional:1445:71: error: invalid abstract parameter type ‘AbstractClass’
         typedef _Bind&lt;__func_type(typename decay&lt;_BoundArgs&gt;::type...)&gt; type;
                                                                         ^
  source_file.cpp:5:7: note:   because the following virtual functions are pure within ‘AbstractClass’:
   class AbstractClass {
         ^
  source_file.cpp:10:18: note:    virtual void AbstractClass::doB()
       virtual void doB() = 0;
                    ^
  source_file.cpp: In function ‘int main()’:
  source_file.cpp:26:72: error: no matching function for call to ‘bind(void (AbstractClass::*)(), AbstractClass&amp;)’
       std::function&lt;void()&gt; func = std::bind(&amp;AbstractClass::doA, *aClass)
                                                                          ^
  In file included from source_file.cpp:2:0:
  /usr/include/c++/5/functional:1462:5: note: candidate: template&lt;class _Func, class ... _BoundArgs&gt; typename std::_Bind_helper&lt;std::__is_socketlike&lt;_Func&gt;::value, _Func, _BoundArgs ...&gt;::type std::bind(_Func&amp;&amp;, _BoundArgs&amp;&amp; ...)
       bind(_Func&amp;&amp; __f, _BoundArgs&amp;&amp;... __args)
       ^
  /usr/include/c++/5/functional:1462:5: note:   substitution of deduced template arguments resulted in errors seen above
  /usr/include/c++/5/functional:1490:5: note: candidate: template&lt;class _Result, class _Func, class ... _BoundArgs&gt; typename std::_Bindres_helper&lt;_Result, _Func, _BoundArgs&gt;::type std::bind(_Func&amp;&amp;, _BoundArgs&amp;&amp; ...)
       bind(_Func&amp;&amp; __f, _BoundArgs&amp;&amp;... __args)
       ^
  /usr/include/c++/5/functional:1490:5: note:   template argument deduction/substitution failed:
  source_file.cpp:26:72: note:   couldn't deduce template parameter ‘_Result’
       std::function&lt;void()&gt; func = std::bind(&amp;AbstractClass::doA, *aClass)
                                                                          ^
  </code></pre>
  
  <p>Is there any solution to my problem? I haven't found one so far.</p>