Re: delete, hash_map
Well, either the object has already been deleted,
or its destructor does an illegal operation (e.g.
maybe a recursion problem?).
It is impossible to tell from the code you've posted.
My code:
#include <hash_map>
stdext::hash_map<moving_vehicle*, COsgCar*> g_hash; //global
variable
typedef pair<moving_vehicle*, COsgCar*> Ptr_Pair;
void COsgView::setRootChild(float x, float y, float z, float angle,
int type, moving_vehicle* pMovingVehicle)
{
/**** new, only hear ****/
COsgCar * osgcar = new COsgCar(x, y, z, angle, type);
g_hash.insert(Ptr_Pair(pMovingVehicle, osgcar));
}
vehicle_node* car_list::delete_car(vehicle_node *k)
{
stdext::hash_map<moving_vehicle*, COsgCar*>::iterator hash_Iter;
hash_Iter = g_hash.find(k->vehicle_p);
if (hash_Iter != g_hash.end())
{
COsgCar *p = g_hash[k->vehicle_p];
g_hash.erase(hash_Iter);
delete p; /**** If I comment, there is no problem ***/
p = NULL;
}
}
A puzzle.
----------------
Regards Lung