A function pointer issue. How to efficiently interface with C API (ie. GSL) from C++ class?
<p>This question seems to have been asked numerous times before, for example <a href="http://www.physicsforums.com/showthread.php?t=235922" rel="nofollow">here1</a>, <a href="http://bytes.com/topic/c/answers/657124-interface-problem" rel="nofollow">here2</a> and <a href="http://www.cplusplus.com/forum/general/10435/" rel="nofollow">here3</a>.</p>

<p>What I am trying to do is, set the member <code>function</code> of the C-Struct <code>gsl_function</code> to a member function of my class.</p>

<pre><code>class MyClass{

    double foo(double x)
    {
        return ...;
    }

    double bar(double x)
    {
        ...
        gsl_function F;
        // Problem I cant do this (compiler error)
        F.function = &amp;(this-&gt;foo);
    }
};
</code></pre>

<p>The third <a href="http://www.cplusplus.com/forum/general/10435/" rel="nofollow">link</a> above provides a solution, I think it is based on the wrapper approach described <a href="http://www.newty.de/fpt/callback.html#member" rel="nofollow">here4</a>.</p>

<p>So my question is can I do better. Is there an easier way? For example, possibly by using Boost's function and Bind objects.</p>

<p>I am weighing up the option of using a gsl wrapper, such as o2scl. But am a bit releuctant as I may pay the price later if the wrapper is not well maintained. Any suggestions?   </p>
