title: Setting a pointer to a non-static member function
body: <p>I'm trying to setup a function pointer that is set during execution based on a set of user parameters. I would like to have the function pointer point to a non-static member function but I can't find how to do it. </p>
  
  <p>The examples I've seen say this can only be done with static member function only or use global variables in straight C.</p>
  
  <p>A simplified example follows:</p>
  
  <pre><code>    class CA
      {
      public:
          CA(void) {};
          ~CA(void) {};
          void setA(double x) {a = x; };
          void setB(double x) {b = x; };
  
          double getA(const double x) {return x*a; };
          double getB(const double x) {return x*b; };
  
          void print(double f(const double), double x) {
              char cTemp[256];
              sprintf_s(cTemp, "Value = %f", f(x));
              std::cout &lt;&lt; cTemp;
          };
  
      private:
          double a, b;
      };
  </code></pre>
  
  <p>The implementation part is</p>
  
  <pre><code>CA cA;
  cA.setA(1.0);
  cA.setB(2.0);
  
  double (*p)(const double);
  
  if(true) {
      p = &amp;cA.getA;  //'&amp;' : illegal operation on bound member function expression
  } else {
      p = cA.getB;  //'CA::getB': function call missing argument list; use '&amp;CA::getB' to create a pointer to member
                    //'=' : cannot convert from 'double (__thiscall CA::* )(const double)' to 'double (__cdecl *)(const double)'
  }
  
  cA.print(p, 3.0);
  </code></pre>
  
  <p>So how do I get p to point to either 'getA' or 'getB' so that it is still useable by 'print'.</p>
  
  <p>From what I have seen, the suggestions are to use boost or std::bind but I've had no experience with either of these. I'm hoping that I don't need to dive into these and that I'm just missing something.</p>
  
  <p>Compiler MSVC++ 2008</p>