👍 g++ -std=c++11 lambda_capture.cpp
👍 ./a.out
11
7
👍 cat lambda_capture.cpp
#include <iostream>
using namespace std;
int main() {
int a = 2, b = 5;
auto calc = [a, &b](int x) {
return a * x + b;
};
int z = 3;
cout << calc(z) << endl;
a = 4;
b = 1;
cout << calc(z) << endl;
}