fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct IntPtr
  5. {
  6. IntPtr(int n = 0) : value(new int(n)) {}
  7. IntPtr(const IntPtr & rhs) : value(new int(*rhs.value)) {}
  8. IntPtr & operator=(IntPtr rhs) { std::swap(value, rhs.value); }
  9. ~IntPtr() { delete value; }
  10. int get() const { return *value; }
  11.  
  12. int * value;
  13. };
  14.  
  15. int main()
  16. {
  17. std::vector<IntPtr> integers(100, -1);
  18.  
  19. for (std::vector<IntPtr>::iterator it = integers.begin(), end = integers.end(); it != end; ++it)
  20. {
  21. std::cout << it->get() << " ";
  22. }
  23. }
Success #stdin #stdout 0s 2960KB
stdin
Standard input is empty
stdout
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1