fork(2) download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. struct Foo
  5. {
  6. Foo() : someValue(5) {};
  7. int someValue;
  8. };
  9.  
  10. std::map<int,Foo*> function_that_returns_the_map()
  11. {
  12. std::map<int,Foo*> myMap;
  13. {
  14. int v = 0;
  15. Foo *b = new Foo();
  16. std::cout << (*b).someValue << std::endl; // PRINTING FOO FIRST
  17. myMap.insert(std::pair<int,Foo*>(v,b));
  18. }
  19.  
  20. // PRINTING FOO AGAIN
  21. std::map<int, Foo*>::iterator it = myMap.begin();
  22. for(it; it != myMap.end(); ++it)
  23. {
  24. std::cout << it->second->someValue << "\n";
  25. }
  26. return myMap;
  27. }
  28.  
  29. int main()
  30. {
  31. std::map<int, Foo*> myMap;
  32. myMap = function_that_returns_the_map();
  33.  
  34. //PRINTING FOO AGAIN.
  35.  
  36. std::map<int, Foo*>::iterator it = myMap.begin();
  37. for (it; it!=myMap.end(); ++it)
  38. std::cout << it->second->someValue << std::endl;
  39. return 0;
  40. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
5
5
5