can someone explain the this in the class ? i havent yet understood what it does
can someone explain the this in the class ? i havent yet understood what it does
this is a pointer to the invoking object. It is used often in overloaded-operator functions that need to return the object for stringing (i.e. n op m op r => n.op(m).op(r) ).
This is why in your previous code, *this was used. That is the actual instance of the invoking object.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
yes but i need a good example
If you have
myClass obj[10];
And you invoke
obj[5].func();
Then the this pointer is the thing which tells you that it's obj[5] that needs to be updated, and not something else.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.