重载运算符

该函数为友元函数 不然是 time<<cout

ostream & operator<<(ostream & os,const Time &t)

{

  os<<XX<<' '<<YY;

  return os;

}

在这里 return os是为了可以连贯的cout

(cout<<1)<<Time;

 

重载运算符 = () [] -> 这四个运算符 只能作为成员函数而不能作为友元函数

 

 Complex operator ++();//前缀自增
 Complex operator ++(int);//后缀自增,参数需要加int

posted @ 2021-06-19 21:33  旅玖旅玖  阅读(29)  评论(0编辑  收藏  举报