So I have multiple methods with different arguments:
class c;
void c::foo1(int a) {
}
void c::foo2(int a, int b) {
}
How do I have a queue/vector of these functions? It doesn't necessarily have to be an std::function object, but I need a way to enqueue the execution of functions.
Your question is a bit vague, but if you already know the target object and the arguments to the call at the time you insert the functions into the queue, you can use a queue of parameterless lambdas:
std::deque<std::function<void()>> q;
c x;
q.push_back( [&x] { x.foo1(1); } );
q.push_back( [&x] { x.foo2(2,3); } );
// ... some time later we might want to execute the functions in the queue ...
while (!q.empty())
{
q.front()();
q.pop_front();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With