I was browsing Qt sources, and noticed this
QUuid &operator=(const GUID &guid)
{
*this = QUuid(guid);
return *this;
}
I've never seen assignment to "this" before. What does assignment to "this" do?
I was browsing Qt sources, and noticed this
QUuid &operator=(const GUID &guid)
{
*this = QUuid(guid);
return *this;
}
I've never seen assignment to "this" before. What does assignment to "this" do?
That is not an assignment to
this
but to the object pointed bythis
. That will effectively calloperator=( 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:
According to the definition of 'operator=' this action copy-converts 'guid' into a new object of type 'QUuid'.