匿名Lambda函数,C++
1 // To Compile and Run: g++ -std=c++11 lambda.cc -Wall -O3 && ./a.out 2 3 4 #include <iostream> 5 6 7 int main() { 8 int c = 12; 9 10 std::cout 11 << 12 [c](int a, int b)->int { 13 std::cout << a + b << "\n"; 14 return c; 15 } (2, 5) 16 << "\n"; 17 18 auto Add = [c](int a, int b)->int { 19 std::cout << a + b << "\n"; 20 return c; 21 }; 22 std::cout << Add(1, 2) << std::endl; 23 return 0; 24 }