I have a class called “Tasks” that needs to store methods from other classes, and be able to execute them. I’d like it to work like this:
Window *window = new Window();
Tasks* tasks = new Tasks();
tasks.m_tasks.Add(window.Create("My Window"));
Then I could call that window creation from my tasks class, by iterating over the stored tasks and executing each one:
tasks.ExecuteTasks();
What would be the datastructure of “m_tasks” that stores the functions, and how could I call them?
I would use a
std::list<std::function<void()> >, orboost::functionifstd::functionis not available.And you’ll need to change the syntax of that
Addcall to avoid executing theCreatemethod right away.C++11:
C++03: