this pointer
Inside any non-static member function, this is a pointer to the object the function was called on.
class Node {
public:
Node& operator=(const Node& other) {
if (this == &other) return *this; // self-assignment check
// ...
return *this; // *this = the actual object, lets callers chain
}
};
Why operator= checks this == &other
node = node; // legal, if weird, C++
Without the check, some implementations of operator= would clear/free this’s data before realizing other was this all along — destroying the very data it was about to copy from.