picec of code

来源:互联网 发布:上海艾诺科软件 编辑:程序博客网 时间:2024/06/05 07:03
#include <iostream>


using namespace std;


class INT{
public:
        friend ostream& operator<<(ostream& os, const INT& i);


        INT(int i): m_i(i){}
        INT& operator++(){
                ++(this->m_i);
                return *this;
        }
        const INT operator++(int){
                INT tmp = *this;
                ++(*this);
                return tmp;
        }


        INT& operator--(){
                --(this->m_i);
                return *this;
        }


        const INT operator--(int){
                INT tmp = *this;
                --(*this);
                return tmp;
        }


        int& operator*(){
                return (int&)m_i;
        }
private:
        int m_i;
};


ostream& operator<< (ostream& os, const INT& i)
{
        os << '[' << i.m_i << ']' << endl;
        return os;
}


int main()
{
        INT I(5);
        cout << I++ << endl;
        cout << ++I << endl;
        cout << I-- << endl;
        cout << --I << endl;
        cout << *(I) << endl;
        return 0;
}