左移运算符是指 <<
#include<iostream>
using namespace std;
class Person
{
public:
int m_A;
int m_B;
};
ostream& operator<<(ostream &cout,Person &p)
{
cout<<"m_A="<<p.m_A<<"m_B="<<p.m_B;
return cout;
}
void test01()
{
Person p;
p.m_A=10;
p.m_B=10;
cout<<p<<" hello"<<endl;
}
int main()
{
test01();
}
一般用全局函数来重载左移运算符
注意 cout的类型是ostream,而且这里要用&的方式来传。