Hello, I am having a problem with my code. I am trying to delete an array, after I created a bigger one, and copied all the values from the previous to the new one, but when i try to delete the old one, I get : heap corruption detected after normal block. Please help me. Here is the code:
this is the add function:
Code:bool IntArrayList::add(Number& num) { if(m_Arr[0] == NULL)///If array is empty put the first element at 0 index { m_Arr[0] = # m_Size += 1; return true; } else { int in_place = SearchInsertPlace();///find the place where you store another element if(in_place != -1)///there is still place available { m_Arr[in_place] = # m_Size += 1; return true; } else///if no free places, create new array { m_Arr = CreateNewArray(m_Arr); in_place = SearchInsertPlace(); m_Arr[in_place] = # return true; } } }
this is the function that creates the new array:
thanks!Code:Number** IntArrayList::CreateNewArray(Number** arr) { m_ArraySize *= 2; Number** newArray = new Number*[m_ArraySize]; for(int i=0 ; i<m_ArraySize ; i++) newArray[i]=NULL; for(int i = 0 ; i < m_Size ; i++ )/// creating new array. { newArray[i] = m_Arr[i]; m_Arr[i]=NULL; } //for(int i = 0 ; i < m_Size ; i++)/// delete old array. // delete m_Arr[i]; delete []m_Arr; return newArray; }




Reply With Quote