- 左移运算符重载
 
- 不要滥用运算符重载,除非有需求
 - 不能对内置数据类型进行重载
 - 对于自定义数据类型,不可以直接用 cout << 输出
 - 需要重载 左移运算符
 - 如果利用成员 函数重载 ,无法实现让cout 在左侧,因此不用成员重载
 - 利用全局函数 实现左移运算符重载
 
- ostream& operator<<(ostream &cout, Person & p1)
 
- 如果想访问类中私有内存,可以配置友元实现
 
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Person
{
	friend ostream& operator<<(ostream &cout, Person & p1);
public:
	Person(int a, int b)
	{
		this->m_A = a;
		this->m_B = b;
	}
	//试图利用成员函数 做<<重载
	//void operator<<( Person & p)    // p.operator<<(cout)    p<<cout
	//{
	//
	//}
private:
	int m_A;
	int m_B;
};
//利用全局函数 实现左移运算符重载
ostream& operator<<(ostream &cout, Person & p1)
{
	cout << "m_A = " << p1.m_A << " m_B = " << p1.m_B;
	return cout;
}
void test01()
{
	Person p1(10, 10);
	cout << p1 << endl;
}
int main(){
	test01();
	system("pause");
	return EXIT_SUCCESS;
}                










