作者isbecky27 ((昵称))
看板C_and_CPP
标题[问题] copy constructor搭配new
时间Tue Apr 16 13:51:51 2019
https://i.imgur.com/3zVRZDc.jpg
我想问一下这段code是哪里危险呢
copy constructor搭配new使用
会产生什麽问题QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.113.141.139
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1555393913.A.B59.html
1F:→ djshen: 你先说说看你觉得B=A会发生什麽事吧04/16 13:55
在create的时候两个的ptr会不一样
B=A会把A里的ptr也复制过去
然後两者的ptr就会相同了
变成联动的
※ 编辑: isbecky27 (140.113.141.139), 04/16/2019 14:01:50
※ 编辑: isbecky27 (140.113.141.139), 04/16/2019 14:03:56
2F:推 Feis: Delete 04/16 14:08
3F:→ S404NotFound: private 04/16 14:26
4F:推 zamperla: 要设定=operator overloading 04/16 15:01
5F:→ sarafciel: 1.B原本new的东西发生什麽事了? 2.B跟A会解构几次? 04/16 15:28
6F:推 chienweichih: 你把B干掉的时候 A的ptr就被干掉了 04/16 17:36
7F:→ samuelcdf: 原本B的ptr不见了,动态配置的记忆体,不用之前要做什麽? 04/17 11:19
8F:→ xavier13540: 这个class又没有copy ctor 04/17 12:05
9F:→ xavier13540: 喔 default的 04/17 12:06
10F:→ loveme00835: void main() 帮哭哭 04/17 13:50
11F:推 adrianshum: 去看看 rule-of-three / rule-of-five / rule-of-zero 04/17 20:02
12F:→ adrianshum: 吧 04/17 20:02
13F:→ shk9cvu5ye: shallow copy 04/18 02:03