Hello, my understanding is 'this' is a pointer to the current class you are working in.
Is this right?
For example in my textbook it has
class ThreeD
{
int x,y,z;
public:
ThreeD() {x=y=z=0;}
ThreeD(int i, int j, int k) {x=i; this ->y =j; z=k;}
ThreeD operator+(ThreeD op2);
ThreeD operator=(ThreeD op2);
void show();
}
ThreeD::ThreeD operator=(ThreeD op2);
{
x=op2.x;
y=op2.y;
z=op2.z;
return *this;
}
I am a bit confused about the return of (*this).
Is it because if you just returned a void the values wouldn't be changed outside this scope.
Basically I am just not 100% confident that I have grasped whats happening here and want to check there isn't something important I'm missing. I can't find a suitable explanation from google. Thanks :).