Hi guys, I am wondering if this is the proper way to do the array expansion...
Does the line "ptr1 = ptr2" cause memory leak? Because initially both ptr1 and ptr2 point to different array of data, by executing that line, i wonder if the "delete[] ptr1" still can delete the array initially pointed by the ptr1
Yes it causes a memory leak. ptr2 = ptr1; is a simple assignment of pointers. If you want to copy the elements from one array to another you will have to use a loop and assign each element individually, or use std::memcpy or something like that.