fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <list>
  4. #include <string>
  5. #include <vector>
  6.  
  7. class foo
  8. {
  9. private:
  10. std::map<std::string, std::list<int>> _allObjs;
  11. std::vector<int*> _someObjs;
  12.  
  13. public:
  14. void addObj(const std::string &name, int obj)
  15. {
  16. _allObjs[name].push_back(obj);
  17. _someObjs.push_back(&_allObjs[name].back());
  18. }
  19.  
  20. void doStuff()
  21. {
  22. for (auto &obj : _someObjs)
  23. {
  24. std::cout << *obj << std::endl;
  25. }
  26. }
  27.  
  28. };
  29.  
  30. int main()
  31. {
  32. foo test;
  33. test.addObj("test1", 5);
  34. test.addObj("test1", 6);
  35.  
  36. test.addObj("test2", 7);
  37. test.addObj("test2", 8);
  38.  
  39. test.doStuff();
  40. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
5
6
7
8