Hi All,
Having an issue with my DynamicArray template class. The remove used to be...
inline void Remove(int in_index) {for (int i=in_index; i < m_count-1; i++) m_array=m_array[i+1]; m_count--;}
but then I realized that for objects, some destructors were not getting called when the item was removed because there was always an old item left hanging at the end of the list. I then went to...
inline void Remove(int in_index)
{
T* newArray=new T[m_arraySize];
// copy members
int newIndex=0;
for (int i=0; i < m_count; i++)
{
if (i != in_index)
newArray[newIndex++]=m_array;
}
// delete old array and replace
delete [] m_array;
m_array=newArray;
}
Which seems to work, but looks grossly inefficient.
Can someone suggest a better implementation considering the object in the array could be an object or a value type?
Thanks
Rael