int padding = 3; auto sum_lambda = [padding](int a, int b) -> int { return a + b + padding; }; std::cout << sum_lambda(1, 2) << std::endl;
4. std::function
C++ 对 std::function 的描述:
Class template std::function is a general-purpose polymorphic function wrapper
Instances of std::function can store, copy, and invoke any CopyConstructible Callabletarget–functions, lambda expressions, bind expressions, or other function objects, as well as pointers to member functions and pointers to data members
// lambda without capturing any value -> function ptr SumFunc func_ptr = [/*padding (error) */](int x, int y) -> int { return x + y; }; std::cout << func_ptr(1, 2) << std::endl;;