Skip to content

Instantly share code, notes, and snippets.

@dridk
Last active September 3, 2018 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dridk/17e664ae13983f0c0d1493600a9f6157 to your computer and use it in GitHub Desktop.
Save dridk/17e664ae13983f0c0d1493600a9f6157 to your computer and use it in GitHub Desktop.
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