#include <iostream>
using namespace std;
class MyTeger{
public:
friend ostream& operator<<(ostream &cout,MyTeger &p);
MyTeger &operator++();
MyTeger operator++(int);
private:
int m_A;
int m_B;
};
int main(){
MyTeger p1;
p1++;
cout<<++p1;
这里前置++正确,但是后置++就报错,请问为什么呢?
return 0;
}
//左移运算符重载
ostream& operator<<(ostream &cout,MyTeger &p){
cout<<"m_A="<<p.m_A<<" m_B="<<p.m_B<<endl;
return cout;
}
//前置递增
MyTeger &MyTeger:: operator++(){
m_A++;
m_B++;
return *this;
}
//后置递增
MyTeger MyTeger::operator++(int){
MyTeger temp=*this;
m_A++;
m_B++;
return temp;;
}