重载函数

(1) 重载输出运算符  <<

ostream& operator<<(ostream& os,Student& s)  //其中Student是一个类类型的数据结构

{

os<<s.GetNO()<<"\t"<<s.GetName()<<"\t"<<s.GetUniversity()<<"\t"<<s.GetTotal();

return os;

}

(2)重载相减运算符 -

Complex operator -(Complex &c1,Complex &c2)

{

Complex tmp;

tmp.a=c1.a-c2.a;

tmp.b=c1.b-c2.b;

return tmp;

}

posted @ 2014-03-27 10:40  zhoudan  阅读(101)  评论(0编辑  收藏  举报