当前位置:网站首页>10 令 operator= 返回一个 reference to *this
10 令 operator= 返回一个 reference to *this
2022-07-26 10:32:00 【JeffyGao】
条款-10 令 operator= 返回一个 reference to *this
- 令赋值(saaignment)操作符返回一个 reference to *this。
常量有以下赋值连锁形式:
int x, y, z;
x = y = z = 15;
// x = ( y = (z = 15) )
// 15先被赋值给z,然后其结果(更新后的z)再被赋值给y,同理赋值给x。
为了实现“连锁赋值”,赋值操作符必须返回一个 reference指向操作符的左侧实参。在 copy assignment操作符里返回 *this 即可:
class widget {
public:
……
widget& operator= ( const widget& rhs ) {
……
return *this;
}
……
};
同理适用于 +=、-+、*=
边栏推荐
- String null to empty string (what does empty string mean)
- 图片随手机水平移动-陀螺仪。360度设置条件
- 【Halcon视觉】图像的傅里叶变换
- Navicat15连接本地虚拟机的Mysql(Centos7)
- Using undertow, Nacos offline logout delay after service stop
- What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?
- Wechat official account release reminder (wechat official account template message interface)
- datav漂亮数据屏制作体验
- Google与Pixar开发Draco支持USD格式 加速3D对象传输<转发>
- Navicat15 MySQL (centos7) connected to local virtual machine
猜你喜欢

js下载文件,FileSaver.js导出txt、excel文件

uniapp使用简单方法signalR(仅用于web调试,无法打包app)
![[Halcon vision] programming logic](/img/1a/b6daac946fbefd8337355dc8b7873e.png)
[Halcon vision] programming logic

Unit test, what is unit test and why is it so difficult to write a single test

2022/07/25 ------ arrangement of strings

数据分析入门 | kaggle泰坦尼克任务(一)—>数据加载和初步观察

【Halcon视觉】编程逻辑
软件打不开了

The CLOB field cannot be converted when querying Damon database

数据库的复习--3.SQL语言
随机推荐
数据库的复习--3.SQL语言
【socket】三次握手是在listen中完成,accept只从完成连接的队列中拿出一个连接
并行、并发及对于高并发优化的几个方向
数据分析入门 | kaggle泰坦尼克任务(一)—>数据加载和初步观察
MLX90640 红外热成像仪测温传感器模块开发笔记(六)
js,e.pageX、pageY模态框拖动
句句解析js中的完美 / 缓冲运动框架(新手专用)
一些你不知道的 web API
RecyclerView最后一条显示不全或显示部分的问题解决
Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
议程速递 | 7月27日分论坛议程一览
【Halcon视觉】算子的结构
Prevent XSS attacks
【Halcon视觉】图像滤波
Tradingview 使用教程
Deduct daily question 838 of a certain day
【C#语言】具名类型和匿名类型
What is wrong about the description of function templates (how to solve link format errors)
About the declaration and definition of template functions [easy to understand]
关于模板函数声明与定义的问题[通俗易懂]