I have a template class called OrdinalObjectList which is simply a map with a key of int and object pointers. It's purpose is to provide an collection of object pointers that can be accessed by an ordinal key. Here is the class:
template <typename O>
class OrdinalObjectList {
public:
std::map<int, O*> List;
OrdinalObjectList() {};
virtual ~OrdinalObjectList()
{
// Need to delete the objects in the map
typename std::map<int, O*>::iterator i;
for (i = List.begin(); i != List.end(); i++)
{
O* d = i->second;
delete d;
}
};
On destruction of the OrdinalObjectList, the destructor loops through the map and deletes the objects. This has worked fine up until now, however it is currently receiving a EXC_BAD_ACCESS error when deleting the second of two objects in the collection.
On the first pass d is 'FSCE::Customer' * 0x10088e600 which delete's without issue. On the second pass, d is 'FSCE::Customer' * 0x100897e00 which, when delete'd causes the EXC_BAD_ACCESS. I can access the members of the second 'd' in the debugger. i.e. d->lifeid int 2, indicating that the FSCE::Customer object is a valid object and that 'd' is a valid pointer.
What steps should I take next to track down the cause of the EXC_BAD_ACCESS?