What does assignment to *this do (*this = val)?

会有一股神秘感。 提交于 2019-12-05 04:26:13

That is not an assignment to this but to the object pointed by this. That will effectively call operator=( QUuid const & ) on the current object.

It just invokes QUuid &operator=(const QUuid& quUid);.

'this' is simply a pointer to the object on which the current method is invoked. Changing the value behind 'this' (by dereferencing the pointer using '*this' and assigning another object) modifies the caller's object to become another one.

In your example, a caller of 'operator=' might do the following:

GUID guid = guid(...) ;
QUuid uid = guid ;

According to the definition of 'operator=' this action copy-converts 'guid' into a new object of type 'QUuid'.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!