intmain(){int m =10;int n =[m]()mutable{m = m +1;cout<<m<<endl;return m;}();// m = 11//如果没有mutable,因为m为值传递 m = m + 1报错
cout<<n<<endl;// n = 11
cout<<m<<endl;// m = 10return0;}
intmain(){int m =10;[&](){m = m +1;}();
cout<<m<<endl;// m = 11return0;}
//Lambda表达式(匿名函数)//[]捕获列表 ()参数列表 ->返回值类型int c =[](int a,int b)->int{return a+b;}(1,2);
cout<<c<<endl;// 3 //也可有以下写法:auto f =[](int a,int b)->int{return a+b;};int c =f(1,2);
cout<<c<<endl;// 3
//Lambda表达式的嵌套int c =[](int n){//返回值类型由编译器自动推导return[n](int x){return n + x;}(2);}(1);
cout<<c<<endl;// 3//也可以有以下写法:
autu f =[](int n){return[n](int x){return n + x;};};int c =f(1)(2);//n = 1 x = 2
cout<<c<<endl;// 3