#include<iostream>
using namespace std;
int main()
{
const int k = 10;
// Capture k by value
auto myl = [k] (int k) { cout << " ++k=" << ++k ; };
myl(k+10);
}
Error below
lamda.cpp: In lambda function:
lamda.cpp:10:50: error: increment of read-only variable âkâ
auto myl = [k] (int k) { cout << " ++K=" << ++k ; };
clearly what I am referring to is local variable K and not const member K.