fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. class MyObj
  5. {
  6. public:
  7. int a;
  8. int b;
  9.  
  10. MyObj( int ai, int bi )
  11. {
  12. cout << "constructor of "<<this << endl;
  13. this->a = ai;
  14. this->b = bi;
  15. }
  16.  
  17. MyObj(const MyObj& other) // copy constructor
  18. {
  19. cout<<"copy constructor of " <<this<<endl;
  20. }
  21.  
  22. ~MyObj()
  23. {
  24. cout<<"destructor of "<<this<<endl;
  25. }
  26.  
  27.  
  28. };
  29.  
  30. vector<MyObj> myVec;
  31.  
  32. void foo()
  33. {
  34. MyObj objInst( 10, 20 );
  35. myVec.push_back( objInst );
  36. }
  37.  
  38. int main() {
  39. cout << "main start" <<endl;
  40. foo();
  41. cout << "main end"<<endl;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 4528KB
stdin
Standard input is empty
stdout
main start
constructor of 0x7ffe34b148e0
copy constructor of 0x562b33017e80
destructor of 0x7ffe34b148e0
main end
destructor of 0x562b33017e80