title: C++ function with a generic and optional class
body: <p>I define this function with a generic (and optional) class object:</p>
  
  <pre><code>template &lt;class OptionalClass = void&gt;
  double galg(std::function&lt;double(std::vector&lt;double&gt;, OptionalClass)&gt; func, std::vector&lt;double&gt;&amp; parameters, OptionalClass extrainfo);
  </code></pre>
  
  <p>And use it as:</p>
  
  <pre><code>double res = galg(fun, par, extra);
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>std::vector&lt;double&gt; par;
  c_myclass extra;
  double fun(std::vector&lt;double&gt; parameters, c_myclass extrainfo);
  </code></pre>
  
  <p>However I keep getting this error:          </p>
  
  <pre><code>error: no matching function for call to ‘galg(double (&amp;)(std::vector&lt;double&gt;, c_myclass), std::vector&lt;double&gt;&amp;, c_myclass&amp;)’
     err = galg(fun, par, extra);
                                                                                                     ^
  In file included from ... note: candidate: ‘template&lt;class OptionalClass&gt; double galg(std::function&lt;double(std::vector&lt;double&gt;, OptionalClass)&gt;, std::vector&lt;double&gt;&amp;, OptionalClass)’
  
   double galg(
          ^~~~~~~~~~~
  ... note:   template argument deduction/substitution failed:
  ... note:   mismatched types ‘std::function&lt;double(std::vector&lt;double&gt;, OptionalClass)&gt;’ and ‘double (*)(std::vector&lt;double&gt;, c_myclass)’
     err = galg(fun, par, extra);
  </code></pre>
  
  <p>Why? What am I doing wrong?</p>