// LambdaDemo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void TestLambda()
{
// 测试Lambda表示式的使用
[]{
cout << "Lambda空" << endl;
}();
// Lambda的其中一种
auto FuncAdd = [](int a, int b)->int {return a + b; };
int xx = FuncAdd(2, 3);
cout << xx << endl;
//[]外部参数
auto FuncMultiPly = [xx](int a)->int {
cout << xx << endl;
cout << a + xx << endl;
return a + xx;
};
int b = 23;
// 隐式捕获
auto FuncHide = [&]{
cout << b << endl;
};
FuncHide();
FuncMultiPly(23);
}
int main()
{
TestLambda();
system("pause");
return 0;
}
运行结果: