Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class TwoDim
  5. {
  6. public:
  7. TwoDim(int x, int y)
  8. {
  9. px=new int;
  10. py=new int;
  11. *px=x;
  12. *py=y;
  13. }
  14. void set(int x, int y)
  15. {
  16. *px=x;
  17. *py=y;
  18. }
  19. private:
  20. int *px, *py;
  21. friend ostream& operator<<(ostream& o, const TwoDim t);
  22.  
  23.  
  24. };
  25.  
  26. ostream& operator<<(ostream& o, const TwoDim t)
  27. {
  28. *t.px=1;
  29. *t.py=2;
  30. o << *t.px << " " << *t.py;
  31. return o;
  32. }
  33.  
  34.  
  35. int main()
  36. {
  37. TwoDim x(1,2), y(10,20);
  38. cout<<x;
  39. x=y;
  40. x.set(100,200);
  41. y.set(1000,2000);
  42. cout<<x<<endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement