Definition:
std::map<unsigned, CItem*> m_map;
void RegisterEvent(unsigned eventID) {
std::map<unsigned, CItem*>::iterator it = m_map.find(eventID); <<< crashes
if (it == m开发者_开发技巧_map.end()) {
m_map[eventID] = new CItem();
}
else {
...
}
}
The marked row crashes in std::less on second call, the first call works. When watching callstack, the __x argument seems WAY off (as the # of events is < 40, but __x is like 2354918952 (or something else big))...
Ideas?
TIA /R
It looks like something has corrupted the memory of your program. This is highly unlikely to be std::map - this just happens to be where the problem manifests itself. You need to look at your own code for the source of the problem.
And not to do with your problem, but GCC 3.4 is pretty ancient - the current release is 4.4.2. You might want to upgrade.
I don't see anything wrong with the code you posted. Since the first call to the function works, I would think that the problem is in the code you didn't post (I would first look at the else
block or after it). Something is making the map invalid.
精彩评论