- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
第六章 运算符重载课件
;;;public:
// 构造函数
zComplex();
zComplex(double r1,double i1);
zComplex(const zComplex c);
zComplex(double c){realpart = (double)c;imagpart = 0;}
// 取复数的实部和虚部
double real();
double imag();
friend double real(const zComplex);
friend double imag(const zComplex);
//运算符重载为成员函数
zComplex operator+(const zComplex);
zComplex operator-(const zComplex);
zComplex operator*(const zComplex);
zComplex operator/(const zComplex);
zComplex operator=(const zComplex); ; //运算符重载为友元函数
friend int operator ==(const zComplex,const zComplex);
friend int operator !=(const zComplex,const zComplex);
// show complex
void print();
};
#endif;运算符;;例 6-2;unarytest1 unarytest1::operator-(const unarytest1 a) const
{
return unarytest1(-a.data);
}
const unarytest1 operator~(const unarytest1 a)
{
return unarytest1(~a.data);
}
const unarytest1 operator!(const unarytest1 a)
{
return unarytest1( !a.data );
}
//主程序
//EXAMPLE6_2.CPP
#include iostream.h
#include ″EXAMPLE6_02.H″
void main()
{ ; unarytest1 ua(5);
+ua;
ua.show();
-ua;
ua.show();
~ua;
ua.show();
!ua;
ua.show();
};例 6-3;例 6-3;;; test(int,int);
test operator++(); // 前缀
test operator++(int); // 后缀
test operator--(); // 前缀
test operator--(int); // 后缀
};
#endif
//EXAMPLE6_03.CPP
#include iostream.h
#include ″EXAMPLE6_03.H″
test::test(int a,int b){t1=a;t2=b;}
test test::operator++()
{
cout ″++test\n″;
t1++;t2++;
return *this;
}
test test::operator++(int)
{
cout ″test++\n″; ;int tmp1=t1;
int tmp2=t2;
t1++;t2++;
return test(tmp1,tmp2);
}
test test::operator--()
{
cout ″--test\n″;
--t1;--t2;
return *this;
}
test test::operator--(int)
{
cout ″test--\n″;
int tmp1=t1;
int tm
您可能关注的文档
最近下载
- 中国帕金森病步态障碍管理专家共识.docx VIP
- Unit 1 Happy Holiday 第1课时(Section A 1a-1d)课件 人教版(2024)八年级英语上册.pptx VIP
- 2025年配煤掺烧技术及混配煤管理.pptx VIP
- 跨境电商创业计划书融资.pptx VIP
- F372A 中文版.pdf VIP
- 正确理解和大力推进中国式现代化PPT课件.ppt VIP
- 24S410建筑特殊单立管排水系统安装.docx VIP
- 心血管危重患者安全转运.pptx VIP
- 关于中建某局新员工转正答辩.ppt VIP
- Unit 1 Happy Holiday Section B(3a-Reflecting)课件 2025人教版英语八年级上册.pptx
文档评论(0)