title: Acquire a function type for a member of a class template?
body: <p>I am trying to write a float(float) function class</p>
  
  <pre><code>#pragma once
  class float_func
  {
      struct concept 
      {
          virtual ~concept() {}
          virtual float operator()(float) = 0;
          virtual concept* clone() = 0;
      };
      template &lt;typename T&gt;
          class impl : public concept
      {
          public:
              impl(const T&amp; ptr) : ptr_(ptr) {};
              virtual float operator()(float arg1) {
                  return ptr_(arg1);
              }
              virtual concept* clone() {
                  return new impl&lt;T&gt;(ptr_);
              }
          private:
              T ptr_;
  
      };
  
      public:
      float_func() { object_ = nullptr; }
      template &lt;typename T&gt; float_func(const T&amp; ptr) : object_(new impl&lt;T&gt;(ptr)) {}
      float_func(const float_func&amp; other) : object_(other.object_-&gt;clone()) {}
      ~float_func() { delete object_; }
      template &lt;typename T&gt; 
      float_func&amp; operator=(const T&amp; ptr) {
          delete object_;
          object_ = new impl&lt;T&gt;(ptr);
          return *this;
      }
      float_func&amp; operator=(const float_func&amp; other) {
          delete object_;
          object_ = other.object_-&gt;clone();
          return *this;
      }
      float operator()(float arg1) {
          return (*object_)(arg1);
      }
      private:
      concept* object_;
  };
  </code></pre>
  
  <p>Try to use it:</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;functional&gt;
      #include "float_func.h"
  
      struct FloatFunctor
      {
          float operator()(float a) {
              return a * 2.f;
          }
      };
  
      float mul3(float a) {
          return a * 3.f;
      }
  
      int main()
      {
          float_func f1 = FloatFunctor();
          float_func f2 = &amp;mul3;
          //float_func f3 = mul3; //! does not compile
          std::function&lt;float(float)&gt; sf = mul3;
          std::function&lt;float(float)&gt; sf2 = &amp;mul3;
          std::cout &lt;&lt; f1(1) &lt;&lt; " " &lt;&lt;  f2(2) &lt;&lt;  " " &lt;&lt; sf(3) &lt;&lt; " " &lt;&lt; sf2(4) &lt;&lt; std::endl;
          return 0;
      };
  </code></pre>
  
  <p><code>float_func f3 = mul3</code> does not compile, but the stl version does compile. </p>
  
  <p>The error message:</p>
  
  <pre><code>float_func.cc
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\xlocale(336) : wa
  rning C4530: C++ exception handler used, but unwind semantics are not enabled. S
  pecify /EHsc
  e:\src\tmp\type_erasure\float_func.h(14) : warning C4180: qualifier applied to f
  unction type has no meaning; ignored
          e:\src\tmp\type_erasure\float_func.h(28) : see reference to class templa
  te instantiation 'float_func::impl&lt;T&gt;' being compiled
          with
          [
              T=float (float)
          ]
          float_func.cc(20) : see reference to function template instantiation 'fl
  oat_func::float_func&lt;float(float)&gt;(T (__cdecl &amp;))' being compiled
          with
          [
              T=float (float)
          ]
  e:\src\tmp\type_erasure\float_func.h(22) : error C2207: 'float_func::impl&lt;T&gt;::pt
  r_' : a member of a class template cannot acquire a function type
  </code></pre>
  
  <p>Could you explain the error? </p>
  
  <p>How does std::function handle this kind of template argument or how could I modify my code to support  <code>float_func f3 = mul3</code>?</p>