Skip to content

Instantly share code, notes, and snippets.

@TakayoshiKochi
Last active August 29, 2015 14:05
Show Gist options
  • Save TakayoshiKochi/8fe80ef6d0f530ac3458 to your computer and use it in GitHub Desktop.
Save TakayoshiKochi/8fe80ef6d0f530ac3458 to your computer and use it in GitHub Desktop.
Practice C++ functor??
#include <iostream>
int add1(int x) {
return ++x;
}
int double2(int x) {
return 2 * x;
}
int tentimes(int (*func)(int), int p) {
int x = 0;
for (int i = 0; i < 10; ++i) {
x += func(p);
}
return x;
}
int main(int argc, char** argv) {
std::cout << tentimes(add1, 2) << std::endl;
std::cout << tentimes(double2, 2) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment