fork(2) download
  1.  
  2. #include <iostream>
  3. #include <list>
  4. #include <functional>
  5. using namespace std;
  6.  
  7. int main() {
  8. int a = 2, b = 6, c = 1;
  9.  
  10. list<reference_wrapper<int>> mylist;
  11. mylist.push_back(a);
  12. mylist.push_back(b);
  13. mylist.push_back(c);
  14.  
  15. for(auto x : mylist) {
  16. cout << x << " ";
  17. }
  18. cout << endl;
  19. a = 3; // <- this setting will modify mylist!
  20.  
  21. for(auto x : mylist) {
  22. cout << x << " ";
  23. }
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
2 6 1 
3 6 1