C++中的lambda

来源:互联网 发布:金融数据公司 编辑:程序博客网 时间:2024/06/11 02:08
#include<functional>#include<iostream>using namespace std;function<int(int, int)> returnLambda(int &a,int b) {//将&a换为int a,则就会出现错误的结果return [&a,b](int x, int y) {a = a + 1;return x*y+a+b;};}int main() {int a = 3, b = 4;auto lf = returnLambda(a,b);cout << lf(12,5) << endl;system("pause");return 0;}