im trying to add more memory space to this stack code using this:
temp = new(nothrow) StackElement[myCapacity + 10];
for (int i = 0; i < myCapacity; i++)
temp[i] = myArray[i];
delete [] myArray;
myArray = temp;
First of all get rid of exit(1) calls, it's not a good idea. Use bool/int return value (or argument in constructor) to indicate success or failure or throw an exception.
> should i use template?
If you want to use Stack class with types other that int then use templates. You can have simpler implementation of Stack class by deriving from (protected/private derivation) or aggregating std::vector/std::list.
Yes, you need another member function.
But again, if you are not writing this code for learning purposes, then better use standard containers. They can do it all for you.