fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a = 0;
  6. auto l = [a]() mutable { cout << ++a << endl; };
  7. cout << "repeated calls of the lambda does change something:" << endl;
  8. l();
  9. l();
  10. l();
  11. cout << "... but a itself hasn't changed. a=" << a << endl;
  12. }
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
repeated calls of the lambda does change something:
1
2
3
... but a itself hasn't changed. a=0