title: C++: Pointer to Member Function within Struct
body: <p>This is a follow up question to my previous post: <a href="https://stackoverflow.com/questions/20623101/c-initializing-struct-and-setting-function-pointer">C++: Initializing Struct and Setting Function Pointer</a></p>
  
  <p>My new question is how do I call a pointer-to-member function within a struct? I have modified my previous code to:</p>
  
  <pre><code>float MyClass::tester(float v){
      return 2.0f*v;
  }
  
  struct MyClass::Example{
      float(Scene_7::*MyFunc)(float);
  
      float DoSomething(float a){
          return (MyFunc)(a);           //ERROR, SEE BELOW FOR OUTPUT
      }
  };
  </code></pre>
  
  <p>I then set the function as follows, and output the result to the call:</p>
  
  <pre><code>struct Example e;
  e.MyFunc = &amp;MyClass::tester;
  std::cerr &lt;&lt; e.DoSomething(1.0f) &lt;&lt; std::endl;
  </code></pre>
  
  <p>I get the following error: must use '.<em>' or '-></em>' to call pointer-to-member function...</p>
  
  <p>The problem is I don't know how to do this. I am guessing I have to call something like <code>this-&gt;*(myFunc)(a)</code> within <code>DoSomething</code> but <code>this</code> references the struct. I have tried searching "this within struct pointer-to-member function" but have not been able to find anything. Any help or suggestions would be great. I feel like I am close but it is just a matter of syntax at this point.</p>