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.
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 error C2597: illegal reference to non-static member
The syntax I have now is (object->*(vector[a].function)) (parameter). Simplified code below:
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<FunctionRelation> func_rel;
}
The pointer to Base is stored in the USERDATA of the window passed to the WndProc function, and thus I have access to the class instance. In WndProc I have:
Base *user_data = reinterpret_cast<Base *>(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 < static_cast<int>(user_data->func_rel.size ());a++)
if (user_data->func_rel[a].message == msg)
return (user_data->*(func_rel[a].function)) (window, wparam, lparam);
return DefWindowProc (window, msg, wparam, lparam);
vectoris a member? (In any case, please post enough code to reproduce the problem; the code you've posted is fine given suitable definitions ofobject,vector,a,functionandparameter, so the problem must be in the definitions of those).user_data->func_rel.size (), althoughfunc_relis private.