title: How to pass method of a class into another function in C++?
body: <p>Say I have a class and a function</p>
  
  <pre><code>class A
  {
      int a;
      int b;
      int mul()
      {
          return a+b;
      }
  };
  ...
  
  void func(int af, int bf, int (*fc)())
  {
      ...
  }
  </code></pre>
  
  <p>In the main function, the function is supposed to use the methods of class A</p>
  
  <pre><code>int main
  {
      A as;
      ...
      func(as.a, as.b, as.mul);
  }
  </code></pre>
  
  <p>However, I can't do that, the compiler keeps telling me that I'm passing </p>
  
  <pre><code>(int&amp;, int&amp;, 'unresolved overloaded function type') 
  </code></pre>
  
  <p>into a function of candidate </p>
  
  <pre><code>(int, int, void(*)()).
  </code></pre>
  
  <p>Why is that, and how to pass method of a class into another function?</p>
  
  <p>Oh, I think I should make the problem a little bit clearer. <code>func(...)</code> is actually a function from an algorithm I'm working on. And <code>class A</code> is a model that will use the algorithm to do the simulation. So I don't think I'll specifically use the instance of A in function B, but only pass A's methods and components in and work with them.</p>
  
  <hr>
  
  <p>Update: Some have mentioned using static methods in class A. However, this is still a partial solution. Using static method <code>mul()</code> will force me to claim a and b both to be static. And if I have to use multiple instances of A, with method a, b different in each instance in my main function, using static variables will simply fail.</p>
  
  <p>So, are there other suggestions on how to fix this without using static variables/methods? I remember in script languages such as python, passing methods of whatever type is basically not an issue. Why can't I do a similar thing in C++? Or are there workarounds in C++ that can help me do this?</p>