I have a program as below:
int main() { int val = 4; auto add = [val](int a)->int{ val += 2; return a+val; }; cout <<
Just capture it by reference, it will work !!
auto add = [&val](int a) -> int{ // }