title: C++ member function pointer with different arguments - or is this bad anyway?
body: <p>Even though I fear that you will tell me that this topic was covered several time, I dare to ask it, since I was not able to generate a solution. Probably I was just looking for the wrong thing...</p>
  
  <p>Assume that I have a function which receives a "mode" from some external function. Depending on the mode, the function will call different member functions of the same object. This works well for me with member function without any argument, but I did not find out how to extend it to members with arguments. In the real world application, the arguments are not int/float but a more complex classes and the call is nested inside different loops, so I would need to put switch statements several times which I consider ugly.</p>
  
  <p>Question A: Is it possible to easily add support for member functions with arguments based on the existing design? If yes, how does one do that? If possible without external libraries...</p>
  
  <p>Question B: Is this a completely wrong/bad approach? How would I do it better?</p>
  
  <p>Thanks a lot for your help and explanations.</p>
  
  <p>Chris</p>
  
  <p>header excerpt:</p>
  
  <pre><code>typedef void (Object::*memberFunction)();
  
  class Object
  {
      void memberFnNoArg();
      void memberFnWithIntArg(int arg);
      void memberFnWithFloatArg(float arg);
  }
  </code></pre>
  
  <p>cpp excerpt:</p>
  
  <pre><code>void function()
  {
      int mode = getModeFromSomewhere();
  
      int intArg = 33;
      float floatArg = 66.6;
  
      switch(mode)
      {
      case 1:
          process(&amp;Object::memberFnNoArg);
          break;
      case 2:
          process(&amp;Object::memberFnWithIntArg, ???); // how can I pass arg?
          break;
      case 3:
          process(&amp;Object::memberFnWithFlaotArg, ???); // how can I pass arg?
          break;
      default:
          // do nothing;
      }
  
  }
  
  void process(Object::memberFunction func)
  {
      Object object;
      // loops, called several times, ...
      (object.*func)(); // how do I handle different arguments?
  }
  </code></pre>