// C++11 std::function test // g++ -std=c++0x std_function.cpp #include #include using namespace std; int square(int x){ cout<<"square\n"; return x*x; } int cube(int x){ cout<<"cube\n"; return x*x*x; } int test1(function f, int x){ return f(x); } int test2(function f, int x){ return f(f(x)); } int main() { function g; for (int i=0;i<10;++i) { if(i<4){ g = square; } else { g = cube; } cout<