Original Post
Hi, I'm using a std::map to contain some dynamically allocated classes within C++. The classes are constructed in the main loop and then added to a std::map, which is then responsible for them. Everything works hunky-dory until I come to clear out the map, when I get nasty errors galore. Here's a link to the error in question: clicky (9Kb). Here's an example of how I'm declaring and using the std::map: The "DeleteForm" line at the bottom is what generates the error in question. Many thanks. [Edited by - eSCHEn on March 25, 2006 9:18:02 PM]
// definition of map type
typedef std::map<std::string, gui::CForm*> TStringFormMap;
// this is how I add a form
bool CApplication::AddForm(gui::CForm* Form)
{
// error checking
if (Form == NULL)
return false;
if (Form->GetName() == "")
return false;
if (m_forms.find(Form->GetName()) != m_forms.end())
return false;
// add form
m_forms[Form->GetName()] = Form;
return true;
}
// this is how I delete a form
void CApplication::DeleteForm(const std::string FormName)
{
if (this->Forms(FormName) != NULL)
{
if (FormName == m_focused_form)
m_focused_form.clear();
gui::CForm* form_del = m_forms[FormName];
delete form_del;
form_del = NULL;
m_forms.erase(FormName);
}
}
// sample usage
gui::CForm form1;
g_application.AddForm(&form1);
// blah...
// kill form
g_application.DeleteForm(form1.GetName()); // bang!