fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Liczba
  5. {
  6. public:
  7. int x,y;
  8. Liczba(int x,int y):x(x),y(y) {}
  9. friend Liczba operator+(const Liczba &a,const Liczba &b) { return Liczba(a.x+b.x,a.y+b.y); }
  10. friend ostream &operator<<(ostream &s,const Liczba &L) { return s<<'('<<L.x<<','<<L.y<<')'; }
  11. };
  12.  
  13. int main()
  14. {
  15. Liczba liczba1(10,20),liczba2(20,30);
  16. cout<<"liczba1: "<<liczba1<<endl;
  17. cout<<"liczba2: "<<liczba2<<endl;
  18. cout<<"suma "<<(liczba1+liczba2)<<endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3456KB
stdin
stdout
liczba1: (10,20)
liczba2: (20,30)
suma (30,50)