fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Class
  6. {
  7. int ourInt;
  8. public:
  9. void set(int temp)
  10. {
  11. ourInt = temp;
  12. }
  13.  
  14. int get()
  15. {
  16. return ourInt;
  17. }
  18. };
  19.  
  20. int main() {
  21. // your code goes here
  22. vector<Class*> classList;
  23. for(int i = 0; i < 10; ++i)
  24. {
  25. Class* c = new Class();
  26. c->set(0);
  27. classList.push_back(c);
  28. }
  29.  
  30. Class* c = new Class();
  31. c->set(1);
  32. classList.erase(classList.begin()+4);
  33. classList.insert(classList.begin()+4, c);
  34.  
  35. int count = 0;
  36. for(auto it = classList.begin(); it != classList.end(); ++it)
  37. {
  38. cout <<"Index: " << count << " result: " << (*it)->get() << endl;
  39. count++;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Index: 0 result: 0
Index: 1 result: 0
Index: 2 result: 0
Index: 3 result: 0
Index: 4 result: 1
Index: 5 result: 0
Index: 6 result: 0
Index: 7 result: 0
Index: 8 result: 0
Index: 9 result: 0