1.递增运算符重载(++x)
using namespace std;
#include<string>
class myinteager{
friend ostream &operator<<(ostream &cout,myinteager myint);
public:
//自定义类型
myinteager(){
m_num=0;
}
//重载++运算符,返回引用为了一直对一个数据进行递增操作
void operator++(){
//先进行++运算
m_num++;
//再将自身做一个返回
return this*;//解引用
}
private:
int m_num;
};
ostream &operator<<(ostream &cout,myinteager myint){
cout<<myint.m_num;
return cout;
}
void test01(){
myinteager myint;
cout<<myint<<endl; //或++myint或++(++myint)
}
int main(){
test01();
return 0;
}
2.后置++