title: wrap c++ method with a c method
body: <p>I have a class:</p>
  
  <pre><code>class C {
  public:
     int func1 (int arg1, int arg2) { return 1; }
     float func2 (float arg1, float arg2) { return 2; }
  } ;
  </code></pre>
  
  <p>I would like to create a C wrapper function for the methods func1 and func2 and then cast it to a void function pointer.</p>
  
  <pre><code>typedef void (*Function)(void);
  typedef Function *FunctionPtr;
  
  FunctionPtr functions[] = {
    (FunctionPtr)&amp;Wrap&lt;&amp;C::func1&gt;::f,
    (FunctionPtr)&amp;Wrap&lt;&amp;C::func2&gt;::f
  };
  </code></pre>
  
  <p>After which I could cast them back to C function pointers and use them:</p>
  
  <pre><code>Class C c;
  
  typedef int (*MyIntFunction)(C *c, int arg1, int arg2);
  MyIntFunction *mif = (MyIntFunction *)functions[0];
  int ri = (*mif)(&amp;c, 1, 2);
  
  typedef float (*MyFloatFunction)(C *c, float arg1, float arg2);
  MyFloatFunction *mff = (MyFloatFunction *)functions[1];
  float rf = (*mff)(&amp;c, 1, 2);
  </code></pre>
  
  <p>I have been experimenting with various templating magics, but have not found the right way so far of doing this.</p>