#include <iostream>
using namespace std;
class MyInteger
{
friend ostream &operator<<(ostream &out, MyInteger &myInt);
public:
MyInteger()
{
m_Num = 0;
}
//重载前置++运算符 返回引用 为了一直对一个数据进行递增操作
MyInteger &operator++()
{
//先进行++运算
m_Num++;
//再将自身做返回
return *this;
}
//重载后置++运算符 返回值
MyInteger operator++(int) // int代表占位参数,可以用于区分前置和后置递增
{
//先 记录当时结果
MyInteger temp = *this;
//后递增
m_Num++;
//最后将记录结果做返回
return temp;
}
private:
int m_Num;
};
ostream &operator<<(ostream &out, MyInteger &myInt)
{
cout << "m_Num = " << myInt.m_Num;
return out;
}
void test01()
{
MyInteger myInt;
cout << ++(++myInt) << endl;
cout << myInt << endl;
}
void test02()
{
MyInteger myInt;
cout << myInt++ << endl;
cout << myInt << endl;
}
int main()
{
test01();
test02();
system("pause");
return 0;
}