fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class A
  8. {
  9. public:
  10. A() {cout << "constructed " << (void*)this << "\n";}
  11. A(const A& a) {cout << "copied " << (void*)(&a) << " to " << (void*)this << "\n"; }
  12. A& operator =(const A& a) {cout << "assigned " << (void*)(&a) << " to " << (void*)this << "\n"; }
  13. ~A() { cout << "destructor called for " << (void*)this << "\n"; }
  14. };
  15.  
  16. int main ()
  17. {
  18. A one, two;
  19.  
  20. vector<A> vec;
  21. cout << "push_back one" << endl;
  22. vec.push_back(one);
  23. cout << "push_back two" << endl;
  24. vec.push_back(two);
  25. //destructor gets called here
  26. return 0;
  27. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
constructed 0xbff229b2
constructed 0xbff229b3
push_back one
copied 0xbff229b2 to 0x970c008
push_back two
copied 0xbff229b3 to 0x970c019
copied 0x970c008 to 0x970c018
destructor called for 0x970c008
destructor called for 0x970c018
destructor called for 0x970c019
destructor called for 0xbff229b3
destructor called for 0xbff229b2