std::bind and std::function
#include <iostream> | |
#include <typeinfo> | |
#include <functional> | |
#include <vector> | |
using namespace std; | |
class Test | |
{ | |
public : | |
int test() { | |
qDebug()<<"test"; | |
return 1; | |
} | |
float test2() { | |
qDebug()<<"test2"; | |
return 3.2; | |
} | |
int test3() { | |
qDebug()<<"test3"; | |
return 10; | |
} | |
}; | |
int main(int argc, char **argv) | |
{ | |
Test * t = new Test; | |
QList<std::function<void()>> deferred; | |
deferred.append(std::bind(&Test::test, t)); | |
deferred.append(std::bind(&Test::test2, t)); | |
deferred.append(std::bind(&Test::test3, t)); | |
for (auto i : deferred) | |
{ | |
i(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment