Advertisement
Timtsa

Int MyClass

Nov 30th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. # include <iostream>
  2. # include <algorithm>
  3. using namespace std;
  4.  
  5.  
  6.  
  7.  
  8. class MyInt
  9. {
  10.     int valuve;
  11. public:
  12.     explicit MyInt(int valuve = 0)
  13.     {
  14.         this->valuve = valuve;
  15.     }
  16.     void print() const
  17.     {
  18.         cout << valuve << endl;
  19.     }
  20.     MyInt operator + (const MyInt & other)
  21.     {
  22.         MyInt temp;
  23.         temp.valuve = this->valuve + other.valuve;
  24.         return temp;
  25.     }
  26.     MyInt operator + (int veluve) const
  27.     {
  28.         return MyInt(this->valuve + valuve);
  29.     }
  30.  
  31.     MyInt operator +=   (const MyInt & other)
  32.     {
  33.         this->valuve += other.valuve;
  34.         return *this;
  35.     }
  36.  
  37.     MyInt& operator++() //префексная форма
  38.     {
  39.         this->valuve++;
  40.         return *this;
  41.     }
  42.     MyInt operator ++(int)
  43.     {
  44.         MyInt temp(*this);
  45.         this->valuve++;
  46.         return temp;
  47.     }
  48.     friend ostream & operator << (ostream & os, const MyInt obj);
  49. };
  50.  
  51. MyInt operator +(int valuve, const MyInt &obj)
  52. {
  53.     return obj + valuve;
  54. }
  55.  
  56. ostream& operator << (ostream & os, const MyInt obj)
  57. {
  58.  
  59.     os << obj.valuve;
  60.     return os;
  61. }
  62.  
  63. void main()
  64. {
  65.     MyInt a1(3), a2(5);
  66.     MyInt a3 = a1 + 10;
  67.     a3.print();
  68.  
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement