c++ (运算符重载 && ++运算符重载)
c++ (运算符重载 && ++运算符重载)
class Person
{
public:
Person(){
m_Num = 10;
}
//前置++ 重载
Person& operator++()
{
this->m_Num++;
return *this;
}
//后置++ 重载
Person operator++(int)
{
//先保存下目前的数据
Person tmp = *this;
m_Num++;
return tmp;
}
int m_Num;
};
ostream& operator<<(ostream& cout,Person p)
{
cout << p.m_Num;
return cout;
}
void text01()
{
Person p1;
// ++p1;//前置++
// p1++;//后置++
cout << ++p1 << endl;
cout << p1++ << endl;
cout << p1 << endl;
}