Original Post
I'm having trouble with some really simple code, relating to dynamic allocation. I wanted to run it by someone else, to make sure I'm doing it correctly. You know how it goes, sometimes. Is this correct? Thanks. -Gauvir_Mucca
void function()
{
int x = 5;
// An array of classes
CClass* m_Classes;
m_Classes = new CClass[x];
// An array of pointers to the classes
CClass** m_Pointers;
m_Pointers = new CClass*[x];
// The ith elementh of the pointer array should point to the ith
// element of the class array. So the ith pointer points to the ith class
for (int i = 0; i < m_Num_Live_Hornets; i++)
{
m_Pointers = &m_Classes;
}
// .... do other stuff ....
// Ok, now free all the memory we allocated
if (m_Classes != NULL)
{
delete [] m_Classes;
m_Classes = NULL;
}
if (m_Pointers != NULL)
{
delete [] m_Pointers;
m_Pointers = NULL;
}
}