求解释自定义运算符的问题
#include<iostream>
using namespace std;
class Person
{
friend ostream& operator << (ostream& cout, Person& p);//作用是定义友元函数,使函数能够访问私有作用域
public:
Person()
{
m_num = 0;
}
Person& operator++()//这是前置递增运算符
{
m_num++;
return *this;
}
Person operator++(int)
{
Person temp = *this;
m_num++;
return temp;
}
private:
int m_num;
};
ostream& operator << (ostream& cout, Person& p)//对左移运算符进行重定义
{
cout << p.m_num;//定义需要输出的数据Person类型的具体成员数据
return cout; //返回retrun是为了后面可以继续链式输出
}
void test01()
{
Person p;
cout << p << endl;
}
void test02()
{
Person j;
cout << ++j << endl;
cout << j << endl;
}
void test03()
{
Person k;
cout << k++ << endl;
cout << k << endl;
}
int main()
{
//test01();
//test02();
test03();
system("pause");
return 0;
}
代码如上,为何只有test03中
cout<<k++<<endl;这一段中间第一个左移运算符提示输出类型不匹配,我已经定义了左移运算符的输出类型了,求解释