C++11的新特性:Lambda表达式
格式
有三种常见格式:
- [ 捕获 ] ( 形参列表 ) -> 返回值{ 执行语句 }
#include<bits/stdc++.h>
using namespace std;
int main(){
int a=1,b=2;
//实际上这里不写形参也行
auto p=[=](int a,int b)->int{
return a+b;};
cout<<p(a,b);
}
执行结果为: 3
- [ 捕获 ] ( 形参列表 ){ 执行语句 }
#include<bits/stdc++.h>
using namespace std;
int main(){
int a=1,b=2;
//不写形参也行
auto p=[=](int a,int b){
return a+b