So I decided to have some pointer fun tonight 🙂
CursorHBList::CursorHBList(UINT iNumHB)
:m_ppCursorHB(nullptr)
,m_iNumHB(iNumHB)
{
if (iNumHB != 0) {
m_ppCursorHB = new CursorHitBox* [iNumHB];
}
}
so you can see, I’ve now dynamically allocated pointer-types.
Those pointers will each point to another (single) object in the heap. (later on, not in code sample)
So I’ve been wondering if I should delete all the pointer-to-object-types pointed to by the pointer-to-pointer-type first, and then delete[] the pointer-to-pointer-type?
Or is there a better way?
EDIT: Without using smart pointers…
As suggested, a better way would be using a container of smart pointers.
However, since you can’t use smart pointers (I don’t know why because all a smart pointer is is a very simple class, you could write your own), you’ll need to loop through the array and
deleteeach pointer, thendelete[]the array, in that order. That’s just what you have to do when you manage your own memory.