fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point
  5. {
  6. int x, y;
  7. public:
  8. Point(int _x=0, int _y=0):x(_x), y(_y) {}
  9. void show();
  10. Point operator+(const Point& p)
  11. {
  12. Point temp(x+p.x, y+p.y);
  13. return temp;
  14. }
  15. };
  16. void Point::show()
  17. {
  18. cout<<x<<" "<<y<<endl;
  19. }
  20.  
  21. template <typename T>
  22. T Add(T a, T b)
  23. {
  24. return a+b;
  25. }
  26.  
  27. template <typename T>
  28. void Swap(T& a, T& b)
  29. {
  30. T temp;
  31. temp = a;
  32. a = b;
  33. b = temp;
  34. return;
  35. }
  36.  
  37. int main() {
  38. // your code goes here
  39. Point p1(1,2);
  40. Point p2(100,200);
  41. p1.show();
  42. p2.show();
  43. Swap(p1,p2);
  44. p1.show();
  45. p2.show();
  46.  
  47. int a = 10;
  48. int b = 20;
  49. Swap(a, b);
  50. cout<<"fff"<<a<<" "<<b<<endl;
  51.  
  52. Point p3=Add(p1,p2);
  53. p3.show();
  54. return 0;
  55. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1 2
100 200
100 200
1 2
fff20 10
101 202