fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point {
  5. int x, y;
  6. public:
  7. Point() {}
  8. Point(int px, int py)
  9. {x = px;y = py;}
  10. void show() {
  11. cout << x << " ";
  12. cout << y << "\n";
  13. }
  14. Point operator+(Point op2);
  15. Point operator,(Point op2);
  16. };
  17.  
  18. // overload comma for Point
  19. Point Point::operator,(Point op2)
  20. {
  21. Point temp;
  22. temp.x = op2.x;
  23. temp.y = op2.y;
  24. cout << op2.x << " " << op2.y << "\n";
  25. return temp;
  26. }
  27.  
  28. // Overload + for Point
  29. Point Point::operator+(Point op2)
  30. {
  31. Point temp;
  32. temp.x = op2.x + x;
  33. temp.y = op2.y + y;
  34. return temp;
  35. }
  36.  
  37. int main()
  38. {
  39. Point ob1(10, 20), ob2( 5, 30), ob3(1, 1);
  40. Point ob4;
  41. ob1 = (ob1, ob2+ob2, ob3);//Why control is not reaching comma operator for ob1?
  42. ob1 = (ob3, ob2+ob2, ob1);//Why control is not reaching comma operator for ob3?
  43. ob4 = (ob3+ob2, ob1+ob3);//Why control is not reaching comma operator for ob3+ob2?
  44. char c;
  45. cin >>c;
  46. return 0;
  47. }
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
10 60
1 1
10 60
1 1
2 2