Help with deleting array of pointers
I've got a class that declares an array of pointers like this:
class RemoraServer : public CommonApplication
//these are the hosts this server maintains data for
int numberOfHosts; //ongoing count of how many hosts we're dealing with right now
}; // end class RemoraServer
later in the code, it sets an index of that array to point to an object, thereby instantiating the object, like this:
I'm convinced the instantiation works, since I can interact with the newly created objects.
host[numberOfHosts] = new RemoraHost(hostName, hostRef, configFile);
//we just gained a new host!
Now I want to delete all the objects and rebuild them, so I was trying this, but it doesn't work:
All of my classes use virtual destructors.
//first destroy all of our current hosts, so we can re-initialize them all
for (int i = 0; i < numberOfHosts; i++)
} //end for
My program SIGSEGV when it tries to delete the host[i], however (according to gdb) it stays within RemoraServer, so I don't think it's a problem with my RemoraHost code.
What am I doing wrong? (more than 1 answer is allowed. :) ). Thanks for any pointers (pun intended).