fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class A
  8. {
  9. public:
  10. int* p;
  11.  
  12. A() : p() {}
  13.  
  14. A(int _) : p(new int(_)) {}
  15.  
  16. A(const A& a) {
  17. p = new int(*a.p);
  18. }
  19.  
  20. A& operator=(const A& a) {
  21. cout << "===\n";
  22. delete p;
  23. p = new int(*a.p);
  24. return *this;
  25. }
  26.  
  27.  
  28. virtual ~A() {
  29. delete p;
  30. }
  31. };
  32.  
  33. void dump(const A& a)
  34. {
  35. std::cout << *a.p << std::endl;
  36. }
  37.  
  38. int main()
  39. {
  40. std::vector<A> v;
  41. v.push_back(A(1));
  42. v.push_back(A(2));
  43. v.push_back(A(3));
  44.  
  45. v.erase(v.begin());
  46.  
  47. std::for_each(v.begin(), v.end(), dump);
  48.  
  49.  
  50. }
  51.  
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
===
===
2
3