fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <functional>
  4.  
  5. class Yoba {
  6. public:
  7. Yoba();
  8. Yoba(const Yoba& r);
  9. auto getW(void);
  10.  
  11. private:
  12. int w;
  13. static int v;
  14. };
  15.  
  16. std::vector<std::reference_wrapper<Yoba>> global_shit;
  17.  
  18. Yoba::Yoba() : w{ v } { ++v; global_shit.push_back(std::ref(*this)); };
  19. Yoba::Yoba(const Yoba& r) : w{ 0 } {};
  20. auto Yoba::getW(void) { return w; }
  21.  
  22. int Yoba::v{ 1 };
  23.  
  24. int
  25. main()
  26. {
  27. Yoba yoba[ 10 ];
  28. for (auto& i : global_shit)
  29. {
  30. std::cout << i.get().getW() << std::endl;
  31. }
  32. return 0;
  33. }
  34.  
  35.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6
7
8
9
10