title: Pass a class member function as a function parameter
body: <p><strong>I have 2 C++ Class questions:</strong> </p>
  
  <p>The 1st question is: How can I make it so I can pass a class member function as a parameter in another function &amp; how can I then run/call that function? And how can I do the same with a class static function. It maybe easier to understand my question by looking at this code:</p>
  
  <pre><code>class DebuggingManager
  {
      string testLog;
  
      bool test1()
      {
           // run test &amp; return whether it passed or failed
      }    
  
      static bool test2()
      {
  
      }
  
      // How can I call a member function?
      void catalogueTest( string testName, bool DebuggingManager::*nMemberFunction )
      {
          testLog += "Status of " + testName + ": " + ((*)nMemberFunction()) + "\n"; 
      }
  
      // How can I call a static function?
      void catalogueTest( string testName, bool DebuggingManager::*nStaticFunction )
      {
          testLog += "Status of " + testName + ": " + DebuggingManager::nStaticFunction() + "\n"; 
      }
  
      // how do I pass a member function or a static function as a parameter in another function 
      bool runTests()
      {
           catalogueTest( "Test of member functin", test1() );
           catalogueTest( "Test of static functin", test2() );
      }
  
  };
  </code></pre>
  
  <p>The 2nd question is: Is it bad(or dangerous) practice to call a class member (or static) function indirectly like the above. I have a feeling this is really bad C++ practice?</p>
  
  <p><strong>EDIT: Implementing advice</strong>
  Thanks for the reply, I have attempted to implement that advice, its alot to get my head around though, would this be correct? </p>
  
  <pre><code>    // I have a feeling that ParameterList is incorect, would I pass the implicit obj as a parameter or is it done automatically like in normal object function calls?
      typedef bool (DebuggingManager::*MemberPointerType)(ParameterList); 
  
      void catalogueTest( tstring testName, DebuggingManager* obj, MemberPointerType *nMemberFunction )
      {
          debugLog += _T("Status of ") + testName + _T(": ") + (obj-&gt;*nMemberFunction)() + _T("\r\n");
      }
  
      void catalogueStaticTest( tstring testName, bool DebuggingManager::nStaticFunction )
      {
          debugLog += _T("Status of ") + testName + _T(": ") + nStaticFunction + _T("\r\n");
      }
  </code></pre>