当前位置:网站首页>11 handle "self assignment" in operator=
11 handle "self assignment" in operator=
2022-07-26 10:40:00 【JeffyGao】
Clause - 11 stay operator= In dealing with “ Self assignment ”
- Make sure that when the object is self assigning operator= Have good behavior . Technology includes comparison “ Source object ” and “ Target audience ” The address of 、 Careful sequence of sentences 、 as well as copy-and-swap.
- Determine if any function operates on more than one object , When more than one object is the same object , Its behavior is still correct .
“ Self assignment ” Easy to use , Although it doesn't make sense , But if not Processing will cause system error .
Law 1 Traditional practice : stay operator= Make one in “ Certificate test ( identity test )” achieve “ Self assignment ” Test purpose of .
widget& widget::operator=( const widget& rhs ){ if ( this == &rhs ) return *this; // Certificate test ( identity test ) // If it's self assignment , Just don't do anything delete pb; pb = new Bitmap( *rhs.pb ); return *this; }Law 2 Copy copies , Give Way operator= It has exceptional security
widget& widget::operator=( const widget& rhs ){ Bitmap* pOrig = pb; // Remember the original pb pb = new Bitmap( *rhs.pb ); // Make pb Point to *pb A copy of delete pOrig; // Delete the original pb return *this; }
边栏推荐
- json_ object_ put: Assertion `jso->_ ref_ count > 0‘ failed. Aborted (core dumped)
- $router和$route的区别
- [leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array
- 剑指Offer(八):跳台阶
- Simple use of json-c Library -- converting JSON files to struct
- 第4期:大学生提前职业技能准备之一
- RT-Thread 学习笔记(一)---配置RT-Thread开发环境
- Zongzi battle - guess who can win
- 超图 影像 如何去除黑边(两种方法)
- el-table实现可编辑表格
猜你喜欢

Issue 6: which mainstream programming language should college students choose
![[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array](/img/9d/5ce5d4144a9edc3891147290e360d8.png)
[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array
![[leetcode daily question 2021/2/14]765. Lovers hold hands](/img/be/8639a05c733638bf0b3fdeb11abccf.png)
[leetcode daily question 2021/2/14]765. Lovers hold hands

Issue 7: how do you choose between curling up and lying flat

英语基础句型结构------起源

SAP ABAP 守护进程的实现方式
![Error[Pe147]: declaration is incompatible with '错误问题](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[Pe147]: declaration is incompatible with '错误问题

RT-Thread 学习笔记(七)---开启基于SPI Flash的elmfat文件系统(中)

Uniapp uses the simple method signalr (only for web debugging, cannot package apps)

uniapp使用简单方法signalR(仅用于web调试,无法打包app)
随机推荐
11 在 operator= 中处理“自我赋值”
使用Geoprocessor 工具
IAR sprintf 浮点 在UCOS 总格式化成0.0的问题
2021-08-13和鹏哥学C语言-数组
[转]ArcGIS中判断两个Geometry之间的关系
构建ARM嵌入式开发环境
SAP ABAP 守护进程的实现方式
父类对子类的引用(父类引用指向子类对象)
Issue 7: how do you choose between curling up and lying flat
剑指Offer(二十):包含min函数的栈
Uninstall Meizu app store
【小程序】onReachBottom 事件为什么不能触发 ?(一秒搞定)
Simple use of json-c Library -- converting JSON files to struct
12 复制对象时勿忘其每一个成分
Navicat15 MySQL (centos7) connected to local virtual machine
Redis docker instance and data structure
[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字
第6期:大学生应该选择哪种主流编程语言
[leetcode每日一题2021/4/23]368. 最大整除子集
.net operation redis string string