Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. friend day operator+=(day& dy, product& prod)
  2. {
  3. dy.ygl+= prod.Yglevod;
  4. dy.bel+= prod.Belok;
  5. dy.gur+= prod.Gur;
  6. dy.kkal+= prod.Kkal;
  7. return dy;
  8. }
  9.  
  10. day& operator+=(const product& prod)
  11. {
  12. ygl+= prod.Yglevod;
  13. bel+= prod.Belok;
  14. gur+= prod.Gur;
  15. kkal+= prod.Kkal;
  16. return *this;
  17. }
  18.  
  19. class A;
  20.  
  21. class B
  22. {
  23. public:
  24. B& operator +=(const A& a);
  25. int y;
  26. };
  27.  
  28. class A
  29. {
  30. private:
  31. int x;
  32.  
  33. friend B& B::operator +=(const A& a);
  34. friend B& operator -=(B& b, A& a);
  35. };
  36.  
  37. B& B::operator +=(const A& a)
  38. {
  39. y += a.x;
  40. return *this;
  41. }
  42.  
  43. B& operator -=(B& b, A& a)
  44. {
  45. b.y -= a.x;
  46. return b;
  47. }
  48.  
  49.  
  50. int main(int argc, const char * argv[])
  51. {
  52. B b;
  53. A a;
  54. b += a;
  55. B c = b -= a;
  56. }
  57.  
  58. #include <iostream>
  59.  
  60. class B;
  61.  
  62. class A
  63. {
  64. public:
  65. friend A & operator +=(A &a, const B &b);
  66.  
  67. explicit A(int x = 0) : x(x) {}
  68.  
  69. std::ostream & out(std::ostream &os = std::cout) const
  70. {
  71. return os << x;
  72. }
  73.  
  74. private:
  75. int x;
  76. };
  77.  
  78. class B
  79. {
  80. public:
  81. friend A & operator +=(A &a, const B &b);
  82.  
  83. explicit B(int y = 0) : y(y) {}
  84.  
  85. std::ostream & out(std::ostream &os = std::cout) const
  86. {
  87. return os << y;
  88. }
  89.  
  90. private:
  91. int y;
  92. };
  93.  
  94. A & operator +=(A &a, const B &b)
  95. {
  96. a.x += b.y;
  97.  
  98. return a;
  99. }
  100.  
  101. int main()
  102. {
  103. A a(10);
  104.  
  105.  
  106. (a += B(20)).out() << std::endl;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement