I am storing the address of an Object in more than one entry in a vector;
At the time of Deallocating the memory, I am retriving the Pointers one by one and Deleting it; The problem is that say &Obj is stored at indexes 1, 3;
delete works first time; But it fails at 3rd index since it has been deleted in the first iteration itself; Could any body help me out to solve this ;
Here is the Sample Code;
class A{//...};
typedef map<int, A*> Type_t;
Type_t MyMap;
A *p = new A();
MyMap[1] = p;
MyMap[2] = p;
MyMap[3] = p;
//...
A* dPtr;
for( Type_t::iterator iter = MyMap.begin(); iter != MyMap.end(); iter++)
{
dPtr = (*iter).second;
delete dptr; //Works fine for the first time, But fails from 2nd Iteration
}
-Narayan