c++ 中this 和 *this区别
生活随笔
收集整理的這篇文章主要介紹了
c++ 中this 和 *this区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
別跟我說, return *this返回當前對象, return this返回當前對象的地址(指向當前對象的指針)。
? ? ? 正確答案為:return *this返回的是當前對象的克隆或者本身(若返回類型為A, 則是克隆, 若返回類型為A&, 則是本身 )。return this返回當前對象的地址(指向當前對象的指針), 下面我們來看看程序吧:
?
[cpp]?view plain?copy
? ? ? 結果為:yes
?
?
? ? ? 再看:
?
[cpp]?view plain?copy
? ? ?結果為:
?
4
no
?
? ? ?最后, 如果返回類型是A&, 那么return *this返回的是當前對象本身(也就是其引用), 而非副本。
總結
以上是生活随笔為你收集整理的c++ 中this 和 *this区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: having and group by
- 下一篇: 理解几个网络硬件(调制解调器、路由器、交