BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #88477同步于 2015/8/30
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

求教拷贝构造函数问题

panluyuan
2015/8/30镜像同步8 回复
point为带拷贝构造函数的类,没有调用拷贝构造函数的是哪一行? point func(point arg) { point local = arg; point* head = new point(local); *head = arg; return *head; } 求大神指导答案及原因,谢谢~
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
zx723机器人#1 · 2015/8/31
【 在 panluyuan 的大作中提到: 】 : point为带拷贝构造函数的类,没有调用拷贝构造函数的是哪一行? : point func(point arg) : { : ................... point func(point arg) // without optimization, copy-constructor is invoked { point local = arg; // copy-constructor point* head = new point(local); // copy-constructor is invoked in new expression *head = arg; // assignment operator return *head; // copy-constructor } 小菜乱猜,只为暖场
romantic机器人#2 · 2015/8/31
厉害 【 在 zx723 的大作中提到: 】 : [code=c] : point func(point arg) // without optimization, copy-constructor is invoked : { : ...................
buptxrc机器人#3 · 2015/8/31
比较容易弄混的就 拷贝构造函数 和 = 吧。 拷贝构造函数,说到底是个构造函数,构造函数是构造新对象的 分不清拷贝构造函数 和 = 的时候就问问自己,构造了新的对象吗?
FromMars机器人#4 · 2015/8/31
嗯,同意楼上说的
HeartMelody机器人#5 · 2015/8/31
说的有理,心服口服 【 在 buptxrc 的大作中提到: 】 : 比较容易弄混的就 拷贝构造函数 和 = 吧。 : 拷贝构造函数,说到底是个构造函数,构造函数是构造新对象的 : 分不清拷贝构造函数 和 = 的时候就问问自己,构造了新的对象吗?
buptxrc机器人#6 · 2015/8/31
分不清拷贝构造函数 和 = 的时候就问问自己,有对象吗?。。 【 在 HeartMelody 的大作中提到: 】 : 说的有理,心服口服
HeartMelody机器人#7 · 2015/9/1
你天天不都是面向对象编程的么 【 在 buptxrc 的大作中提到: 】 : 分不清拷贝构造函数 和 = 的时候就问问自己,有对象吗?。。 来自「北邮人论坛手机版」
panluyuan机器人#8 · 2015/9/1
多谢,受益匪浅 【 在 zx723 的大作中提到: 】 : [code=c] : point func(point arg) // without optimization, copy-constructor is invoked : { : ...................