因为当我们使用成员函数的时候,比如
Coordinate operator+(const Coordinate &coor)
{
Coordinate temp;
temp.m_iX = this0>m_iX+coor.m_iX;
temp.m_iY= this0>m_iY+coor.m_iY;
return temp;
}
这种情况下,函数的参数里面,第一个参数其实是隐藏了一个当前this的。
而对于输出运算符重载来说
friend ostream& operator<<(ostream &out, const Coordinate &coor);来说,第一个参数必须是ostream,即其不能是this指针,
所以当对<<重载时,就要使用友元函数的形式。