fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class WrongDestructor
  8. {
  9. private:
  10. int number;
  11. public:
  12. WrongDestructor(int number_) :
  13. number(number_)
  14. {}
  15.  
  16. // Copy constructor
  17. WrongDestructor(WrongDestructor const& copied)
  18. : number(copied.number)
  19. {
  20. cout << "Copied " << this->number << endl;
  21. }
  22.  
  23. ~WrongDestructor() {
  24.  
  25. cout<<"Destructor of " <<number<<endl;
  26.  
  27. // throw int();
  28. }
  29. };
  30. int main(int argc, char *argv[])
  31. {
  32. std::vector<WrongDestructor> wrongs;
  33.  
  34. for(int i = 0; i < 10; ++i) {
  35. wrongs.push_back(WrongDestructor(i));
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
Copied 0
Destructor of 0
Copied 1
Copied 0
Destructor of 0
Destructor of 1
Copied 2
Copied 0
Copied 1
Destructor of 0
Destructor of 1
Destructor of 2
Copied 3
Destructor of 3
Copied 4
Copied 0
Copied 1
Copied 2
Copied 3
Destructor of 0
Destructor of 1
Destructor of 2
Destructor of 3
Destructor of 4
Copied 5
Destructor of 5
Copied 6
Destructor of 6
Copied 7
Destructor of 7
Copied 8
Copied 0
Copied 1
Copied 2
Copied 3
Copied 4
Copied 5
Copied 6
Copied 7
Destructor of 0
Destructor of 1
Destructor of 2
Destructor of 3
Destructor of 4
Destructor of 5
Destructor of 6
Destructor of 7
Destructor of 8
Copied 9
Destructor of 9
Destructor of 0
Destructor of 1
Destructor of 2
Destructor of 3
Destructor of 4
Destructor of 5
Destructor of 6
Destructor of 7
Destructor of 8
Destructor of 9