fork download
  1. #include <vector>
  2. #include <functional>
  3. #include <iostream>
  4.  
  5. class test
  6. {
  7. public:
  8. int number;
  9. test(int pass) : number(pass) {}
  10. };
  11.  
  12. int main()
  13. {
  14. test x(1), y(2);
  15.  
  16. std::vector<std::reference_wrapper<test>> z{ std::ref(x), std::ref(y) };
  17.  
  18. x.number = 5;
  19. y.number = 3;
  20.  
  21. std::cout << z[0].get().number << std::endl; // 5
  22. std::cout << z[1].get().number << std::endl; // 3
  23. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
5
3