C++前置自增运算符重载和后置自增运算符重载
#include<iostream>
using namespace std;
class hui
{
friend ostream& operator<<(ostream &cout, hui &yu);
public:
hui()
{
m_A = 10;
}
public:
//前置自增运算符重载
hui& operator++()
{
m_A++;
return *this;
}
hui& operator++(int)
{
hui tem= *this;
m_A++;
return tem;
}
private:
int m_A;
};
ostream& operator<<(ostream &cout, hui &yu)
{
cout << yu.m_A;
return cout;
}
void text01()
{
hui yu1;
cout << ++yu1 << endl;
}
void text02()
{
hui yu2;
cout << yu2++ << endl;
}
int main()
{
//text01();
text02();
system("pause");
return 0;
}