I have an std::map that is working, but there are problems when I try to empty it. The declaration looks like this:
I can put data in the map and read the data. The structure has an array that is created dynamically. The code to delete the arrays looks something like this. (I write something because I cannot cut and paste so please excuse typos.)
Is this the correct way to remove all the entries from a std::map?
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
Code:
std::map< int, DP_MESSAGE_STRUCT * > m_dp_messages;
std::map< int, DP_MESSAGE_STRUCT * >::iterator m_msg_iterator;
Code:
m_msg_iterator = m_dp_messages.begin();
bool empty = m_dp_messages.empty(); // false when I get a problem
while( m_msg_iterator != m_dp_messages.end() )
{
temp = m_msg_iterator->second;
delete[] temp->buffer; // the structure contains an array pointer.
m_dp_messages.erase( m_msg_iterator);
m_msg_iterator = m_dp_messages.begin();
}
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)