المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : DestructElements() and destructor not getting called



C++ Programming
04-09-2010, 09:40 PM
I'm missing something totally fundamental here but have yet to figure it out. I've got a class called JOBINFO. I create instances of it on the heap and add those pointers to a map. When I need to reuse the map, I call its RemoveAll() method. Internally, that method is supposed to call the overridden DestructElements() which then calls each object's destructor. That is not happening.

class JOBINFO
{
public:
JOBINFO()
{
TRACE("Constructor\n"); // gets called
}
~JOBINFO()
{
TRACE("Destructor\n"); // does not get called
}
};
...
void AFXAPI DestructElements( JOBINFO* pJobInfo, int nCount )
{
TRACE("DestructElements()\n"); // does not get called
}
...
// declare the map
CMap m_mapJobInfo;
...
// add an object to the map
m_mapJobInfo.SetAt(123, new JOBINFO);
...
m_mapJobInfo.RemoveAll();Any ideas?

"One man's wage rise is another man's price increase." - Harold Wilson

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

"Man who follows car will be exhausted." - Confucius