博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
侯捷C++学习(二)
阅读量:4557 次
发布时间:2019-06-08

本文共 664 字,大约阅读时间需要 2 分钟。

#include <iostream>

using namespace std;
class complex
{
public:
complex (double r= 0, double i = 0)
:re (r) , im(i)
{ }
complex operator += (const complex& c)
{
this->re = c.re + this->re;
this->im = c.im + this->im;
return * this;
}
double real () const {return re;}
double imag () const {return im;}
private:
double re,im;
friend complex&_dopal (complex*,const complex&);
};
ostream & operator<< (ostream & os, const complex& x)
{
return os<< '(' << x.real () <<','
<< x.imag () <<'(';
}
//尽量不要 pass by value 引用就是一个指针
int main()
{
complex c(1,2), d(2,3),e(1,1),a(5,5);
a += c += d;
cout << a;
return 0;
}

转载于:https://www.cnblogs.com/chuxinbubian/p/10092870.html

你可能感兴趣的文章
【JAVASCRIPT】React学习-组件生命周期
查看>>
win 64 文件操作
查看>>
Java范例集锦(二)
查看>>
C语言变量和常量
查看>>
LInuxDay8——shell脚本编程基础
查看>>
topcoder 673
查看>>
Java中一些常用的类,包,接口
查看>>
下载特定区域内街景照片数据 | Download Street View Photos within Selected Region
查看>>
StarUML 破解方法
查看>>
C语言结构体
查看>>
[转]Tribon船体生产设计应用
查看>>
easy ui datagrid 让某行复选框不能选中
查看>>
第六周作业
查看>>
关于adb端口被占用的解决办法
查看>>
php 部分内置函数的使用
查看>>
字符串处理技巧
查看>>
归档及压缩命令
查看>>
Mybatis步骤
查看>>
WPF自定义控件之扩展原生控件
查看>>
《区块链100问》笔记整理——42~49问
查看>>