Your code didn't handle s3 = s3;
well. You referenced s3.stackArray
after deleting it.
One way to fix this issue is to add if (this == &rightOp) return *this;
in the beginning of operator=()
.
Also, since your initial capacity is 0, and you always grow it by reserve(stackCap * 2)
, it always stuck at 0. Either use non-0 initial capacity or specially handle 0.