#include <iostream>
#include <string>
using namespace std;
class person{
friend ostream & operator<<(ostream &cout,person &p);
public:
person(){
ma=0;
}
//int是占位符,可以区分前置与后置
person operator++(int){
person tp = *this;
ma++;
return tp;
}//重载后置++运算符
private:
int ma;
};
ostream & operator<<(ostream &cout,person &p){
cout << p;
return cout;
}
void test(){
person p;
cout << p++ << endl;
cout << p << endl;
}
int main(){
test();
system("pause");
return 0;
}
#include <string>
using namespace std;
class person{
friend ostream & operator<<(ostream &cout,person &p);
public:
person(){
ma=0;
}
//int是占位符,可以区分前置与后置
person operator++(int){
person tp = *this;
ma++;
return tp;
}//重载后置++运算符
private:
int ma;
};
ostream & operator<<(ostream &cout,person &p){
cout << p;
return cout;
}
void test(){
person p;
cout << p++ << endl;
cout << p << endl;
}
int main(){
test();
system("pause");
return 0;
}
