Overloading Assignment Operator, this pointer
Hi, i'm confused about these lines of code:
(this is in the POV of me talking to the creator of a book thats why im saying you guys(as in the writers of the book))
Code:
String& operator=(const String& rhs) //Assignemt operator
{
if(this == &rhs)
return *this;
int len = strlen(rhs.mData);
delete[] mData;
mData = new char[len+1];
for(int i=0;i<len;++i)
{
mData[i] = rhs.mData[i];
}
mData[len] = '\0'
return *this;
}
i dont get why you put, this == &rhs , does it mean if the address this is pointing to is the same as the address of rhs?
and also when u guys used the bracket operator in the for loop is it like a replacement for dereferencing the pointer to them?
and why did u guys return *this when the return value is a String&? what does String& mean, does it mean a reference to a String object? i dont get it why return *this, does *this mean that you dereferenced the object calling it and then you return the actual object?
and can you explain on what the this pointer is? i dont really get what it is.