fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Object {
  5.  
  6. public:
  7. Object(int id){
  8. cout << "Construct(" << id << ")" << endl;
  9. m_id = id;
  10. }
  11.  
  12. Object(const Object& obj){
  13. cout << "Copy-construct(" << obj.m_id << ")" << endl;
  14. m_id = obj.m_id;
  15. }
  16.  
  17. Object& operator=(const Object& obj){
  18. cout << m_id << " = " << obj.m_id << endl;
  19. m_id = obj.m_id;
  20. return *this;
  21. }
  22.  
  23. ~Object(){
  24. cout << "Destruct(" << m_id << ")" << endl;
  25. }
  26. private:
  27. int m_id;
  28.  
  29. };
  30.  
  31. int main(){
  32. Object v1(1);
  33. cout << "( a )" << endl;
  34. Object v2(2);
  35. v2 = v1;
  36. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Construct(1)
( a )
Construct(2)
2 = 1
Destruct(1)
Destruct(1)