运算符重载中 类定义的对象前置的++可以输出,后置++输出不了,请问是为什么啊?
c++
#include <iostream>
#include <string>
using namespace std;
class my_integer
{
friend ostream& operator<< (ostream& cout, my_integer& i);
public:
my_integer()
{
m_num = 0;
}
my_integer& operator++ ()
{
this->m_num++;
return *this;
}
my_integer operator++ (int)
{
my_integer temp = *this;
m_num++;
return temp;
}
private:
int m_num;
};
ostream& operator<< (ostream& cout, my_integer& i)
{
cout << "m_num: " << i.m_num;
return cout;
}
void test01()
{
my_integer i;
cout << ++i<< endl;
cout << i << endl;
}
void test02()
{
my_integer j;
cout << j++ << endl; // 为什么输出不了j++啊???
cout << j << endl;
}
int main()
{
test01();
test02();
system("pause");
return 0;
}
```****