Created
April 13, 2018 05:58
-
-
Save trnila/bd3aa8d3fa24f15865a0787720bb7a6a to your computer and use it in GitHub Desktop.
c++ bind
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 <vector> | |
#include <functional> | |
void test(int a, int b) { | |
printf("%d %d\n", a, b); | |
} | |
void testStr(const char* a) { | |
printf("%s\n", a); | |
} | |
int main() { | |
std::vector<std::function<void()>> fns; | |
fns.push_back(std::bind(&test, 10, 20)); | |
fns.push_back(std::bind(&test, 1000, 2000)); | |
fns.push_back(std::bind(&testStr, "hello")); | |
fns.push_back(std::bind(&testStr, "world")); | |
for(auto &fn: fns) { | |
fn(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment