title: std::bind and std::function with polymorphism, base class
body: <p>I'm trying to bind an object to a function, but the base's class function is being called.
  The code it's just an example for the real code.
  I will only have the string later in the real code.</p>
  
  <pre><code> class A {
      public:
          virtual void f(const std::string &amp;s) {
              std::cout &lt;&lt; "A " &lt;&lt; s &lt;&lt; std::endl;
          }
      };
  
      class B : public A {
      public:
          void f(const std::string &amp;s) override {
              std::cout &lt;&lt; "B " &lt;&lt; s &lt;&lt; std::endl;
          }
      };
  
      void main() {
          std::unique_ptr&lt;A&gt; a = std::make_unique&lt;B&gt;();
  
          std::function&lt;void(const std::string &amp;)&gt; callback
                  =  std::bind(&amp;A::f, *a, std::placeholders::_1);
          callback("my string");
      }
  </code></pre>
  
  <p>The result is</p>
  
  <pre><code> A my string
  </code></pre>
  
  <p>I tried to change it to &amp;B:f, but got an error.</p>
  
  <pre><code>No viable conversion from 'typename _Bind_helper&lt;__is_socketlike&lt;void (B::*)(const basic_string&lt;char&gt; &amp;)&gt;::value, void (B::*)(const basic_string&lt;char&gt; &amp;), A &amp;, const _Placeholder&lt;1&gt; &amp;&gt;::type' (aka '_Bind&lt;void (Centerity::Cluster::Correlation::B::*(Centerity::Cluster::Correlation::A, std::_Placeholder&lt;1&gt;))(const std::basic_string&lt;char&gt; &amp;)&gt;') to 'std::function&lt;void (const std::string &amp;)&gt;' (aka 'function&lt;void (const basic_string&lt;char&gt; &amp;)&gt;')
  </code></pre>
  
  <p>I tried to change it to <code>A* a = B();</code> same result.
  Couldn't find a similar code anywhere.
  Of course creating <code>B b</code> will call <code>B::f</code>, but that's not helping me.  </p>
  
  <p>I can lose the bind and use lambda, but I don't know how.</p>