fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point
  5. {
  6. public:
  7. Point()
  8. : mX(0)
  9. , mY(0)
  10. {
  11. cout << "Point()" << endl;
  12. }
  13.  
  14. Point(int x, int y)
  15. : mX(x)
  16. , mY(y)
  17. {
  18. cout << "Point(int x, int y)" << endl;
  19. }
  20.  
  21. Point & operator=(const Point & point)
  22. {
  23. cout << "Point & operator=(const Point & point)" << endl;
  24. if (this == &point)
  25. {
  26. return *this;
  27. }
  28. mX = point.getX();
  29. mY = point.getY();
  30. return *this;
  31.  
  32. }
  33.  
  34. Point(const Point & point)
  35. {
  36. cout << "Point(const Point & point)" << endl;
  37. *this = point;
  38. }
  39.  
  40. Point(Point&& point) noexcept
  41. : mX(point.getX())
  42. , mY(point.getY())
  43. {
  44. cout << "Point(Point&& point) noexcept" << endl;
  45. }
  46.  
  47. Point & operator=(Point && point)
  48. {
  49. cout << "Point & operator=(Point && point)" << endl;
  50. if (this != &point)
  51. {
  52. mX = point.getX();
  53. mY = point.getY();
  54. }
  55. return *this;
  56. }
  57.  
  58. int getX() const
  59. {
  60. return mX;
  61. }
  62.  
  63. int getY() const
  64. {
  65. return mY;
  66. }
  67.  
  68. private:
  69. int mX;
  70. int mY;
  71. };
  72.  
  73. Point func()
  74. {
  75. Point t(1, 1);
  76. return t;
  77. }
  78.  
  79. int main() {
  80. // your code goes here
  81. Point p = func();
  82. cout << p.getX() << " " << p.getY() << endl;
  83. return 0;
  84. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Point(int x, int y)
1 1