I have a program as below:
int main() { int val = 4; auto add = [val](int a)->int{ val += 2; return a+val; }; cout <<
The operator () of a lambda is implicitly const unless the lambda is declared mutable - and you can't modify the data members in a const member function. This happens regardless of the type of the capture.
operator ()
const
mutable