Can somebody help me understand how to correctly create and manage a dynamic array? This is what I've got so far:
But, since I am new to C/C++, I am not sure if this is correct. Also, is this the correct way to declare a pointer to an array?Code:CItem* lpItems = NULL; unsigned int nItemCount = 0; // When I want to resize the array I would do this??? if (lpItems) delete[] lpItems; nItemCount++; lpItems = new CItem[nItemCount] // And to cleanup the memory I would do this??? delete[] lpItems;
Any and all help is apprecitated. I can deal with pointers, and arrays don't bother me too much, but when you combine the two it gives me headaches. It makes me really appreciate how easy VB makes it lookCode:CItem* lpItems[]; // Seems like this would be an array of pointers and not a pointer to an array. CItem[]* lpItems; // Or maybe this???
Code:' All in two lines of code :) ReDim Preserve arrayName(newArraySize) As CItem Erase arrayName





Reply With Quote