title: Calling a Member Function Pointer in Static Function
body: <p>The title is pretty descriptive. I have stored a non-static pointer to a member function in a vector of a structure that store member function pointers in my class, and I need a static function in the class to call that function.</p>
  
  <p>I have access to the class instance in my static function, but I still can't seem to call the member function through the pointer b/c of an error message <code>error C2597: illegal reference to non-static member</code></p>
  
  <p>The syntax I have now is <code>(object-&gt;*(vector[a].function)) (parameter)</code>. Simplified code below:</p>
  
  <pre><code>class Base
  {
      private:
          struct FunctionRelation
          {
              UINT message;
              LRESULT (Base::*function) (HWND, WPARAM, LPARAM);
          };
  
          static LRESULT CALLBACK WndProc (HWND window, UINT msg, WPARAM wparam, LPARAM lparam);
  
          std::vector&lt;FunctionRelation&gt;   func_rel;
  }
  </code></pre>
  
  <p>The pointer to Base is stored in the USERDATA of the window passed to the <code>WndProc</code> function, and thus I have access to the class instance. In <code>WndProc</code> I have: </p>
  
  <pre><code>Base *user_data = reinterpret_cast&lt;Base *&gt;(GetWindowLongPtr (window, GWLP_USERDATA));
  
  //Loop through our function relations and call those functions. Else, just return DefWindowProc.
  if (user_data != NULL) //If it is not directly after we created a window.
      for (int a = 0;a &lt; static_cast&lt;int&gt;(user_data-&gt;func_rel.size ());a++)
          if (user_data-&gt;func_rel[a].message == msg)
              return (user_data-&gt;*(func_rel[a].function)) (window, wparam, lparam);
  
  return DefWindowProc (window, msg, wparam, lparam);
  </code></pre>