Guest User

Untitled

a guest
Dec 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // Copy Constructor
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class Myclass {
  8. public:
  9. Myclass() {
  10. cout << "default constructor" << endl;
  11. }
  12.  
  13. Myclass(const Myclass &r)
  14. {
  15. cout << "***********************************" << endl;
  16. cout << "copy constructor" << endl;
  17. cout << "this = " << this << endl;
  18. cout << "&r = " << &r << endl;
  19. cout << "***********************************" << endl;
  20. }
  21.  
  22. };
  23.  
  24. int main()
  25. {
  26. Myclass m1;
  27. Myclass m2{m1}; //C++11
  28.  
  29. cout << "&m1 = " << &m1 << endl;
  30. cout << "&m2 = " << &m2 << endl;
  31.  
  32.  
  33.  
  34. return 0;
  35. }
  36.  
  37. /*
  38. default constructor
  39. ***********************************
  40. copy constructor
  41. this = 0x7ffee3f4c450
  42. &r = 0x7ffee3f4c458
  43. ***********************************
  44. &m1 = 0x7ffee3f4c458
  45. &m2 = 0x7ffee3f4c450
  46. */
Add Comment
Please, Sign In to add comment