What is the assignment of * this do (* this = val)?

I looked through the Qt sources and noticed this

QUuid &operator=(const GUID &guid) { *this = QUuid(guid); return *this; } 

I have never seen the destination of "this" before. What does the assignment of "this" do?

+7
source share
3 answers

This is not an assignment of this , but an object that this points to. This will effectively call operator=( QUuid const & ) for the current object.

+15
source

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

+4
source

'this' is just a pointer to the object that the current method is being called on. Changing the value behind 'this' (by dereferencing a pointer using '* this' and assigning another object) changes the object of the calling object to become different.

In your example, the calling operator "operator =" can do the following:

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

According to the definition of "operator =", this action copies "guid" into a new object of type "QUuid".

+1
source

All Articles