- #include <iostream>
- using namespace std;
- class one
- {
- public:
- one(){}
- one(int i):b(i){}
- const one& operator++()
- {
- ++b;
- return *this;
- }
- const one operator++(int)
- {
- one ret(b);
- ++b;
- return ret;
- }
- const one& operator--()
- {
- --b;
- return *this;
- }
- const one operator--(int)
- {
- one ret(b);
- --b;
- return ret;
- }
- friend const one operator+(const one& left,const one& right)
- {
- return one(left.b + right.b);
- }
- friend const one operator-(const one& left,const one& right)
- {
- return one(left.b - right.b);
- }
- friend ostream& operator<<(ostream& os,const one& right)
- {
- return os << right.b;
- }
- private:
- int b;
- };
- int main()
- {
- one tone(5);
- ++tone;
- cout << tone << endl;
- tone++;
- cout << tone << endl;
- --tone;
- cout << tone << endl;
- tone--;
- cout << tone << endl;
- one a(5),b(6),c(7);
- cout << a+b-c << endl;
- return 0;
- }