Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- # include <algorithm>
- using namespace std;
- class MyInt
- {
- int valuve;
- public:
- explicit MyInt(int valuve = 0)
- {
- this->valuve = valuve;
- }
- void print() const
- {
- cout << valuve << endl;
- }
- MyInt operator + (const MyInt & other)
- {
- MyInt temp;
- temp.valuve = this->valuve + other.valuve;
- return temp;
- }
- MyInt operator + (int veluve) const
- {
- return MyInt(this->valuve + valuve);
- }
- MyInt operator += (const MyInt & other)
- {
- this->valuve += other.valuve;
- return *this;
- }
- MyInt& operator++() //префексная форма
- {
- this->valuve++;
- return *this;
- }
- MyInt operator ++(int)
- {
- MyInt temp(*this);
- this->valuve++;
- return temp;
- }
- friend ostream & operator << (ostream & os, const MyInt obj);
- };
- MyInt operator +(int valuve, const MyInt &obj)
- {
- return obj + valuve;
- }
- ostream& operator << (ostream & os, const MyInt obj)
- {
- os << obj.valuve;
- return os;
- }
- void main()
- {
- MyInt a1(3), a2(5);
- MyInt a3 = a1 + 10;
- a3.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement