重置++后置运算符,发生错误。
第47行有问题,求解答!

#include <string>
#include <iostream>
using namespace std;
//重载递增运算符
class MyInteger
{
friend ostream& operator<<(ostream& cout, MyInteger& myint);
public:
MyInteger()
{
m_Num = 0;
}
//重置前置++运算符 返回引用是为了一直对一个数据进行递增操作
MyInteger& operator++()
{
//先进行++运算
m_Num++;
//再将自身做返回
return *this;
}
//重置后置++运算符 加int与前置作区分
MyInteger operator++(int) //后置返回值,因为temp是有作用域的;如果返回引用则是局部对象temp的引用,temp被释放掉
{
//先 记录当时结果
MyInteger temp = *this;
//再++
this->m_Num++;
//后 返回结果
return temp;
}
private:
int m_Num;
};
//重载左移运算符
ostream& operator<<(ostream& cout, MyInteger& myint)
{
cout << myint.m_Num;
return cout;
}
void test3()
{
MyInteger myint;
cout << myint << endl;
cout << ++myint << endl;
cout << myint << endl;
cout << myint++ << endl;
}
int main()
{
test3();
return 0;
}
