Because this is a pointer (i.e., type Stack* ), not a reference (i.e., not type Stack& ).
We use if(this == &stack) only to ensure approval
s = s;
can be processed correctly (especially when you need to delete something in an old object). Comparing pointers is true only when both are the same object. Of course, we could compare the meaning
if (*this == stack) return *this; else { ... }
But the operation == can be very slow. For example, if your stack has N elements, *this == stack will take N steps. Since the assignment itself takes only N steps, this will double the effort for nothing.
source share