intmain() { Functional = TestFunc; int result = Functional(10); //10 cout << "TestFunc:"<< result << endl; Functional = lambdaFn; result = Functional(22.00); //22 cout << "Lambda:"<< result << endl; Functor testFunctor; Functional = testFunctor; result = Functional(30); //30 cout << "Functor:"<< result << endl; TestClass testObj; Functional = std::bind(&TestClass::ClassMember, testObj, std::placeholders::_1); result = Functional(40); //40 cout << "TestClass:"<< result << endl; Functional = TestClass::StaticMember; result = Functional(50); //50 cout << "TestClass(static):"<< result << endl; return0; }
function is a kind of wrapper,which provides a way to handle several funtion-like forms uniformly. If you know polymorphism, then this is easy to understand.