Last active
August 29, 2015 14:05
-
-
Save TakayoshiKochi/8fe80ef6d0f530ac3458 to your computer and use it in GitHub Desktop.
Practice C++ functor??
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> | |
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