I have a pointer to an array:
I want to double the array size when the array becomes to small. This is how I'm doing it, but its not working correctly. For some reason it gets rid of the first element:Code:T *array = new T[capacity];
Can anyone point out what I'm doing wrong?Code:template<typename T> void ArrayStack<T>::doubleArraySize() { capacity *= 2; T *tempArray = array; array = new T[capacity]; for (int i=0; i<=tos; i++) { array[i] = tempArray[i]; } array = tempArray; delete[] tempArray; }
When I print it should say:
3
2
1
instead:
3
2
some address



LinkBack URL
About LinkBacks


