title: Pointer to member function of an object
body: <p>I would like to integrate a function with gsl. Therefor I have to define a function <code>f</code> (the integrant, which has to be of the form <code>double (*)(double, void*)</code>). For the call of the gsl integration method I need to define a struct, which contains a pointer to a function (this struct is called <code>gsl_function</code>).</p>
  
  <pre><code>gsl_function F;
  F.function = &amp;MyClass::my_f;
  </code></pre>
  
  <p>The function <code>f</code> must be implemented in a class (in the same class from which the integration procedure should be called). How can I assign the pointer above correctly, since the 2nd line is not compiling and leads to the error:</p>
  
  <pre><code>cannot convert ‘double (MyClass::*)(double, void*)’ to ‘double (*)(double, void*)’ in assignment.
  </code></pre>
  
  <p>Here the definition of <code>my_f</code></p>
  
  <pre><code> struct my_f_params { double a; double b;};
  
     double my_f (double x, void * p) {
     struct my_f_params * params = (struct my_f_params *)p;
     double a = (params-&gt;a);
     double b = (params-&gt;b);
     return 1.0/(sqrt(a * (1.0 + x)*(1.0 + x)*(1.0 + x) + (1-a) * std::pow((1.0 + x), (3.0 * (1.0 + b))))); 
      }
  </code></pre>