Quote Originally Posted by pdk5 View Post
Thanks a lot 2kaud. Looks like the iterator is invalid..

std::map<std:: pair<string, u32>, CPGW::CreateSessInfo>::iterator it =
CPGW::m_mSessionId2CCRNum2CreateSessionInfo.find(std::make_pair(sessionid, ccreqnum));;

if( it != CPGW::m_mSessionId2CCRNum2CreateSessionInfo.end())
{
CreateSessInfo stCrSessInfo(it->second);

// Do some processing
}
else
{
LogError("Invalid Iterator in CPGW::OnPCRFCCA " );
}

It is going into LogError..Not sure if there is any issue with calling the iterator for the map with two keys
"Invalid Iterator" might be a missleading message here. Or at least. Not very helpful. It is only a consequence of the fact that key you are looking for is missing. So "Key not found in CPGW::OnPCRFCCA" would be more useful here. You could also log said key.

Not sure what you mean by "Not sure if there is any issue with calling the iterator for the map with two keys"? You are basically just creating a map with a single key, which is a pair, and a pair has a defined sorting order. So it is a completely fine approach.

An added bonus (if you care about ordering), is that your elements will be sorted according to lexicographical ordering. EG: Sort first by the first key, then the second.

If you don't care about ordering at all, consider using an unordered_map instead. That will, however, require you write your own hash. Which is a bit complicated, so only do it if you feel comfortable with it.

PS: typedef's and auto are your friend.