#include<iostream>
using namespace std;
class INT
{
friend ostream& operator<<(ostream& os,const INT& i);
public:
INT(int i):m_i(i){};
//prefix:increament and then fetch
INT& operator++()
{
++(this->m_i);//随着class的不同,该行应该有不同的操作
return *this;
}
//prefix:fetch and then increment
const INT operator++(int)
{
INT temp = *this;
++(*this);
return temp;
}
//prefix:decrement and then fetch
INT& operator--()
{
--(this->m_i);
return *this;
}
//prefix:fetch and then decrement
const INT& operator--(int)
{
INT temp = *this;
--(*this);
return temp;
}
//dereference
int& operator*() const
{ return (int&)m_i;}
private:
int m_i;
};
ostream& operator<<(ostream& os,const INT& i)
{
os<<'['<<i.m_i<<']';
return os;
}
int main()
{
INT I(5);
cout<<I++;//[5]
cout<<++I;//[7]
cout<<I--;//[7]
cout<<--I;//[5]
cout<<*I;//5
}