I am trying to pass two functions OnUserCreate
and OnUserUpdate
as parameters to another function which is then supposed to call them. However, I am getting an error saying
no suitable constructor exists to convert from "int()" to "std::function<int()>"
Here is a reproducible example that vaguely mimics my code.
//ERROR IN LINE win.ProcessMessage(OnUserCreate, OnUserUpdate);
#include <functional>
class Window
{
public:
//std::function<int()> creates a function that returns int and takes
//no parameter...or so i read not sure if this is right either
void ProcessMessage(std::function<int()> create, std::function<int()> update)
{
create();
update();
}
};
class App
{
private:
Window win;
private:
int OnUserCreate()
{
return 1;
}
int OnUserUpdate()
{
return 1;
}
public:
void Run()
{
win.ProcessMessage(OnUserCreate, OnUserUpdate);
}
};
int main()
{
App app;
while (true)
{
app.Run();
}
}