I am working on an assignment to create a container class for a dynamic array of strings. I know this would be far better done with a std::vector, but that is not the 'pointer' of the assignment.
From what I can tell, my program hangs during the delete [] lineArray step below.
MyBag::MyBag()
{
nLines = 0;
lineArray = new std::string[0] ();
}
void MyBag::ResizeArray(int newLength)
{
std::string *newArray = new std::string[newLength];
//create new array with new length
for (int nIndex=0; nIndex < nLines; nIndex++)
{
newArray[nIndex] = lineArray[nIndex];
//copy the old array into the new array
}
delete[] lineArray; //delete the old array
lineArray = newArray; //point the old array to the new array
nLines = newLength; //set new array size
}
void MyBag::add(std::string line)
{
ResizeArray(nLines+1); //add one to the array size
lineArray[nLines] = line; //add the new line to the now extended array
nLines++;
}
The entire program is here http://pastebin.com/KnL4XmAw