运算符重载 :
函数名字为 : 关键字operator后面接需要重载的运算符符号
函数原型 : 返回值类型 operator操作符(参数列表)
成员函数都会有一个隐含的this指针,this始终指向运算符(从左向右)第一个参数的对象
运算符重载函数作为成员函数时 , 参数列表中显式定义的参数个数 , 需要
比实际的参数少一个 .
例 : bool operator==(const Date& d1,const Date& d2){}
是成员函数时 :
bool operator==(const Date& d){
return _y == d._y
&& _m == d._m
&& _d == d._d;
}
调用
if(operator==(d1,d2))
如果运算符重载不是成员函数 if(operator==(d1,d2))
常用简写形式 : if(d1==d2)
原文:https://www.cnblogs.com/enjoyC/p/14702676.html