fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Obj
  6. {
  7. public:
  8. Obj(int moose);
  9. ~Obj();
  10.  
  11. private:
  12. int* val;
  13. };
  14.  
  15.  
  16. Obj::Obj(int num)
  17. {
  18. val = new int;
  19.  
  20. *val = num;
  21. }
  22.  
  23.  
  24. Obj::~Obj()
  25. {
  26. cout << "Cleanup" << endl;
  27. delete val;
  28. }
  29.  
  30. int main() {
  31. std::vector<Obj*> objs;
  32.  
  33. Obj* o = new Obj(10);
  34.  
  35. objs.push_back(o);
  36.  
  37. auto it = objs.begin() + 0;
  38. delete *it;
  39. objs.erase(it);
  40.  
  41. cout << "Finished" << endl;
  42. return 0;
  43. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Cleanup
Finished