当前位置:网站首页>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;
}
……
};
同理适用于 +=、-+、*=
边栏推荐
- Okaleido ecological core equity Oka, all in fusion mining mode
- 抓包工具fiddler和wireshark对比
- 链式方法调用的事务问题剖析
- INSTALL_ FAILED_ SHARED_ USER_ Incompatible error resolution
- 原生JS-获取transform值 x y z及rotate旋转角度
- 2022pta usual training questions (1-10 string processing questions)
- json-c库的简单使用——将json文件转换为struct.
- Wechat official account release reminder (wechat official account template message interface)
- 利用原生js实现自定义滚动条(可点击到达,拖动到达)
- About automatic operation on Web pages
猜你喜欢
centos8(liunx)部署WTM(ASP.NET 5)使用pgsql
软件打不开了
Okaleido ecological core equity Oka, all in fusion mining mode
【Halcon视觉】编程逻辑
js下载文件,FileSaver.js导出txt、excel文件
[Halcon vision] image filtering
The CLOB field cannot be converted when querying Damon database
videojs转canvas暂停、播放、切换视频
【Halcon视觉】算子的结构
INSTALL_ FAILED_ SHARED_ USER_ Incompatible error resolution
随机推荐
Redis realizes distributed lock and gets a watchdog
利用原生js实现自定义滚动条(可点击到达,拖动到达)
datav漂亮数据屏制作体验
抓包工具fiddler和wireshark对比
【Halcon视觉】图像滤波
C语言计算日期间隔天数
面试第一家公司的面试题及答案(一)
json_object_put: Assertion `jso->_ref_count > 0‘ failed.Aborted (core dumped)
卸载魅族应用商店
Prevent XSS attacks
[Halcon vision] software programming ideas
PLC概述
hx711 数据波动大的问题
2022/07/25 ------ arrangement of strings
STM32 阿里云MQTT esp8266 AT命令
Unit test, what is unit test and why is it so difficult to write a single test
PLC overview
数据分析入门 | kaggle泰坦尼克任务(一)—>数据加载和初步观察
js 获得当前时间,时间与时间戳的转换
MLX90640 红外热成像仪测温传感器模块开发笔记(六)