I know I know function pointers are evil
But in this case for what I want to do it comes in handy were it not that this is creating an error :(
please help me solve it good people of Gamedev
class System
{
typedef bool (*menufp)();
typedef std::map<std::string, menufp> mfpmap;
public:
void AddFunction(MouseEvent a_Event, std::string a_MenuItemName, menufp a_Function);
bool ExecuteFunction(MouseEvent a_Event, std::string a_MenuItemName);
void RegisterFunctions();
bool AddButton();
private:
mfpmap mHoverFunctionMap;
void System::AddFunction(MouseEvent a_Event, std::string a_MenuItemName, menufp a_Function)
{
mHoverFunctionMap[a_MenuItemName] = a_Function;
}
void System::RegisterFunctions()
{
AddFunction(MouseEvent::HOVER, "root.Window.Window_Button_2", &System::AddButton);
}
bool System::ExecuteFunction(MouseEvent a_Event, std::string a_MenuItemName)
{
return mHoverFunctionMap[a_MenuItemName]();
}
bool System::AddButton()
{
return true;
}
which gives me the following error in RegisterFunctions():
system.cpp(111) : error C2664: 'System::AddFunction' : cannot convert parameter 3 from 'bool (__thiscall System::* )(void)' to 'System::menufp'
1> There is no context in which this conversion is possible