#include<iostream>
using namespace std;
class Person
{
friend ostream & operator<<(ostream &cout, Person &P);
public:
Person(int A)
{
m_A = A;
}
//自增运算符重载
Person operator++(int)
{
Person P1 = *this;
m_A++;
return P1;
}
private:
int m_A;
};
//左移运算符重载
ostream & operator<<(ostream &cout, Person &P)
{
cout << P.m_A;
return cout;
}
void text()
{
Person P(10);
cout << P++ << endl;
cout << P << endl;
}
int main()
{
text();
system("pause");
return 0;
}
为什么 cout << P++ << endl这段代码出错了。