以成员函数形式进行重载
class complex{
public:
complex operator+(const complex&x)const{};
以全局函数形式进行重载
class complex{
friend complex operator+(const complex&c1,const complex&c2);
……
}
complex operator+(const complex&c1,const complex&c2){}
操作符的前置和后置(区别
class counter{
public:
counter operator++()//前置的++重载
counter &operator++()//前置的++重载
counter operator++(int)//后置的++重载,存在占位参数
counter operator++(int)//后置的++重载,存在占位参数
}
重载++(–)时,如果没有特殊处理,它们的后置用法使用与前置用法相同的重载函数。