Using copy constructor for overload operator=

I am working on a overlaoding the operator=. Can anyone tell me why this doesn't work if my copy constructor works fine?

1
2
3
4
5
6
template <class T>
Stack<T> Stack<T>::operator = (const Stack & right)
{                                                                           
   Stack newStack(right); //uses copy constructor
   return newStack;
}
Your assignment operator doesn't change 'this'. Remember that 'this' is the object on the left side of the = operator. So logically if you want a = b; to modify 'a', then the = operator must modify 'this'.
Topic archived. No new replies allowed.