Pointers to C++ class mthods
<p>Whilst refactoring some legacy C++ code I found that I could potentially remove some code duplication by somehow defining a variable that could point to any class method that shared the same signature.  After a little digging, I found that I could do something like the following:</p>

<pre><code>class MyClass
{
protected:
    bool CaseMethod1( int abc, const std::string&amp; str )
    {
     cout &lt;&lt; "case 1:" &lt;&lt; str;
     return true;
    }

    bool CaseMethod2( int abc, const std::string&amp; str )
    {
     cout &lt;&lt; "case 2:" &lt;&lt; str;
     return true;
    }

    bool CaseMethod3( int abc, const std::string&amp; str )
    {
     cout &lt;&lt; "case 3:" &lt;&lt; str;
     return true;
    }

public:
    bool TestSwitch( int num )
    { 
     bool ( MyClass::*CaseMethod )( int, const std::string&amp; );

     switch ( num )
     {
      case 1: CaseMethod = &amp;MyClass::CaseMethod1;
        break;
      case 2: CaseMethod = &amp;MyClass::CaseMethod2;
        break;
      case 3: CaseMethod = &amp;MyClass::CaseMethod3;
        break;
     }

     ...

     bool res = CaseMethod( 999, "hello world" );

     ...

     reurn res;
    }
};
</code></pre>

<p>My question is - <strong>is this the correct way to go about this?</strong>  Should I consider anything that <em>Boost</em> has to offer?</p>

<p>Edit...</p>

<p>Ok, my mistake - I should be calling the method like so:</p>

<pre><code>bool res = ( (*this).*CaseMethod )( 999, "Hello World" );
</code></pre>
