匿名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 << "
";
14                 return c;
15             } (2, 5)
16         << "
";
17 
18     auto Add = [c](int a, int b)->int {
19         std::cout << a + b << "
";
20         return c;
21     };
22     std::cout << Add(1, 2) << std::endl;
23     return 0;
24 }
原文地址:https://www.cnblogs.com/xiaochou/p/13664213.html