title: "No matching function for call to... unresolved overloaded function type"
body: <p>I am trying to create a library where the user can modify the behaviour of a function on an instance-level and still manage to access the members of this instance. This post is the continuation of <a href="https://stackoverflow.com/questions/24206909/template-and-class-heritance">this thread</a> which is the continuation of <a href="https://stackoverflow.com/questions/24195579/class-member-function-as-function-pointer">this one</a>. Praetorian <a href="https://stackoverflow.com/questions/24206909/template-and-class-heritance?noredirect=1#comment37378887_24206909">suggested me</a> to use std::function/bind to do that. Unfortunately, I have two errors:</p>
  
  <p>Pb #1:  <strong>error: no matching function for call to ‘Child1::BindIt()’</strong></p>
  
  <p>Pb #2: <strong>error: no match for ‘operator=’ (operand types are ‘std::function’ and ‘std::_Bind_helper)(const double&amp;), Child1<em>, const std::_Placeholder&lt;1>&amp;>::type {aka std::_Bind(Child1</em>, std::_Placeholder&lt;1>))(const double&amp;)>}’)</strong></p>
  
  <p>I don't understand how to solve these problems.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  #include &lt;functional&gt;
  
  using namespace std;
  
  
  template&lt;typename T,typename D&gt; T fcn_default(const D &amp;obj, const T &amp;phit){
      return 3.2 + phit;
  }
  
  template&lt;typename T&gt; class Parent{
      public:
          Parent() {}
  
          T do_something(const T &amp;phit){
              return this-&gt;fcn_ptr(phit);
          }
  
          std::function&lt;T(const T&amp;)&gt; fcn_ptr;
  
  };
  
  
  template&lt;typename T&gt; class Child1 : public Parent&lt;T&gt;{
      public:
          Child1() {
              BindIt( &amp;fcn_default&lt; T , Child1&lt;T&gt; &gt; ); // Pb #1: here
          }
          void BindIt(T (*ptr_in)(const T &amp;) ){
              Parent&lt;T&gt;::fcn_ptr = std::bind(&amp;ptr_in, this, std::placeholders::_1); // Pb #2: here
          }
  };
  
  template&lt;typename T&gt; class Child2 : public Parent&lt;T&gt;{
      public:
          Child2() {
              BindIt( &amp;fcn_default&lt; T , Child2&lt;T&gt; &gt; ); // Pb #1: and here
          }
          void BindIt(T (*ptr_in)(const T &amp;) ){
              Parent&lt;T&gt;::fcn_ptr = std::bind(&amp;ptr_in, this, std::placeholders::_1);
          }
  
          T param2;
  };
  
  
  template&lt;typename T&gt; T fcn_mod1   (const Child1&lt;T&gt; &amp;obj, const T &amp;phit){
      return 1.2 + phit;
  }
  template&lt;typename T&gt; T fcn_mod2   (const Child2&lt;T&gt; &amp;obj, const T &amp;phit){
      return 2.2 + phit + obj.param2*0.001;
  }
  
  
  
  typedef double lrtType;
  
  int main(){
      std::vector&lt; Parent&lt;lrtType&gt; * &gt; objects;
  
      Child1&lt;lrtType&gt; *test11 = new Child1&lt;lrtType&gt;();
      objects.push_back(test11);
  
      Child1&lt;lrtType&gt; *test12 = new Child1&lt;lrtType&gt;();
      //test12-&gt;BindIt(&amp;fcn_mod1);
      objects.push_back(test12);
  
      Child2&lt;lrtType&gt; *test2 = new Child2&lt;lrtType&gt;();
      //test2-&gt;BindIt(&amp;fcn_mod2);
      test2-&gt;param2 = 4;
      objects.push_back(test2);
  
      for (size_t i = 0; i &lt; objects.size(); ++i) {
          std::cout &lt;&lt; objects[i]-&gt;do_something(2) &lt;&lt; std::endl;
      }
  
      std::cout &lt;&lt; "test" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><strong>+++++ UPDATE +++++</strong></p>
  
  <p>I updated the code but I still have problem #2</p>
  
  <p>Pb #2: <strong>error: no match for ‘operator=’ (operand types are ‘std::function’ and ‘std::_Bind_helper)(const double&amp;), Child1<em>, const std::_Placeholder&lt;1>&amp;>::type {aka std::_Bind(Child1</em>, std::_Placeholder&lt;1>))(const double&amp;)>}’)</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  #include &lt;functional&gt;
  
  using namespace std;
  
  
  template&lt;typename T,typename D&gt; T fcn_default(const D &amp;obj, const T &amp;phit){
      return 3.2 + phit;
  }
  
  template&lt;typename T&gt; class Parent{
      public:
          Parent() {}
          virtual T do_something (const T &amp;phit) const = 0;
  };
  
  
  template&lt;typename T&gt; class Child1 : public Parent&lt;T&gt;{
      public:
          Child1() {
              Child1&lt;T&gt;::BindIt( &amp;fcn_default&lt; T , Child1&lt;T&gt; &gt; );
          }
          void BindIt(T (*ptr_in)(const Child1 &amp;, const T &amp;) ){
              fcn_ptr = std::bind(&amp;ptr_in, this, std::placeholders::_1); // Problem here
          }
          std::function&lt;T(const Child1 &amp;, const T &amp;)&gt; fcn_ptr;
          T do_something(const T &amp;phit) const {
              return this-&gt;fcn_ptr(*this,phit);
          }
  };
  
  template&lt;typename T&gt; class Child2 : public Parent&lt;T&gt;{
      public:
          Child2() {
              Child2&lt;T&gt;::BindIt( &amp;fcn_default&lt; T , Child2&lt;T&gt; &gt; );
          }
          void BindIt(T (*ptr_in)(const Child2 &amp;, const T &amp;) ){
              fcn_ptr = std::bind(&amp;ptr_in, this, std::placeholders::_1); // And here
          }
          std::function&lt;T(const Child2 &amp;, const T &amp;)&gt; fcn_ptr;
  
          T do_something(const T &amp;phit) const {
              return this-&gt;fcn_ptr(*this,phit);
          }
  
          T param2;
  };
  
  
  template&lt;typename T&gt; T fcn_mod1   (const Child1&lt;T&gt; &amp;obj, const T &amp;phit){
      return 1.2 + phit;
  }
  template&lt;typename T&gt; T fcn_mod2   (const Child2&lt;T&gt; &amp;obj, const T &amp;phit){
      return 2.2 + phit + obj.param2*0.001;
  }
  
  
  
  typedef double lrtType;
  
  int main(){
      std::vector&lt; Parent&lt;lrtType&gt; * &gt; objects;
  
      Child1&lt;lrtType&gt; *test11 = new Child1&lt;lrtType&gt;();
      objects.push_back(test11);
  
      Child1&lt;lrtType&gt; *test12 = new Child1&lt;lrtType&gt;();
      //test12-&gt;BindIt(&amp;fcn_mod1);
      objects.push_back(test12);
  
      Child2&lt;lrtType&gt; *test2 = new Child2&lt;lrtType&gt;();
      //test2-&gt;BindIt(&amp;fcn_mod2);
      test2-&gt;param2 = 4;
      objects.push_back(test2);
  
      for (size_t i = 0; i &lt; objects.size(); ++i) {
          std::cout &lt;&lt; objects[i]-&gt;do_something(2) &lt;&lt; std::endl;
      }
  
      std::cout &lt;&lt; "test" &lt;&lt; std::endl;
  }
  </code></pre>