今天看到的一个有趣面试题:return *this和return this有什么区别?_return*this-CSDN博客

网站介绍:文章浏览阅读4.4w次,点赞68次,收藏187次。别跟我说, return *this返回当前对象, return this返回当前对象的地址(指向当前对象的指针)。 正确答案为:return *this返回的是当前对象的克隆或者本身(若返回类型为A, 则是克隆, 若返回类型为A&, 则是本身 )。return this返回当前对象的地址(指向当前对象的指针), 下面我们来看看程序吧:#include using namespace std;class A{public: int x; A_return*this