-
-
Save dridk/525ce5ebcfcfda2c347d7dc5998ae61d to your computer and use it in GitHub Desktop.
std::bind and std::function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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