but why it said that the return value is: *this
as far as i know, this is a pointer, which means an address/ reference. while *this means the value and not the reference...
but how if it's a function? a function return a value, if it return value like *this then it's not a reference right? *this is a value from the address that referenced by it right?
First things first a reference is not a pointer, it is the object by a different name.
So, this is a self referencing pointer[1], it points to the object the holds the pointer. When you deference the this pointer (*this) you get the object that the pointer points to. The object is then returned. Try not to get hung-up on how the underling implementation actually carries this out, just think that a reference (&) is the object, not a copy of or a point to an object.
_______________________
[1] referencing as in the natural language meaning not a C++ reference type.
hmm... i understand this part, but by the way, is this way is legal? i just did know... i guess i know it now (about this ampersand complicated stuff). unless there's anything you would like to say... thanks man...
i got it. so setC only make the T becomes an independent variable because it return only copy of the other T variable. i'm a little bit confused at first, but this is a good example man...
Right, setC returns a copied T, which in turn copies it's member variable z (default behavior.) Where as, setR returns a reference, which will return the object (the actual object, not a copy) pointed to by this.