码迷,mamicode.com
首页 > 其他好文 > 详细

return this 和return * this

时间:2018-11-22 00:07:04      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:函数   产生   this   turn   返回   ret   区别   指针   return   

this是指向自身对象的指针,*this是自身对象。

也就是说return *this返回的是当前对象的克隆或者本身(若返回类型为A, 则是克隆, 若返回类型为A&, 则是本身 )。

return this返回当前对象的地址(指向当前对象的指针)

this:只存在于类内非静态成员函数中,因为静态成员函数为这个类的所有对象所共有,不用this来区别

this指针是指一个类,在实例化(生成对象时产生)

return this 和return * this

标签:函数   产生   this   turn   返回   ret   区别   指针   return   

原文地址:https://www.cnblogs.com/ymd12103410/p/9998327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!