Re: stl map with two keys
Quote:
iterator is giving some wrong garbage.
Have you checked that the iterator is not .end() - ie key not found?
Also you have
Code:
std::map<std:: pair<string, u32>, CPGW::CreateSessInfo> CPGW::m_mSessionId2CCRNum2CreateSessionInfo;
...
it = m_mSessionId2CCRNum2CreateSessionInfo.find(std::make_pair(sessionid, ccreqnum));
using namespace CPGW in the first but not in the second?
Re: stl map with two keys
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
Re: stl map with two keys
Quote:
Originally Posted by
pdk5
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.
Re: stl map with two keys
Thanks a lot monarch_dodra for hints and useful suggestions...
I think it was my mistake, there was some issue in the wrongly hardcoding of the second key somewhere..We donot have a good debug and test setup..so took sometime to identify this.
Being a newbie to c++, stl, your help and comments are really appreciated
Re: stl map with two keys
Quote:
Being a newbie to c++, stl,
You might find these sites of interest
http://www.cplusplus.com/reference/ and clicking through the various header files
http://www.cplusplus.com/doc/tutorial/
http://www.learncpp.com/
There's also a whole range of various(fairly expensive!) books on c++ and the STL. I would suggest
Professional c++ (Third edition)
http://www.amazon.co.uk/Professional...sional+c%2B%2B
The various books by Scott Meyers
The c++ Standard Library Second Edition
http://www.amazon.co.uk/books/dp/032...=stl+reference
Re: stl map with two keys
Thanks a lot Kaud..
I have ScottMayers STL book, but I find it bit advanced..(may be when i started coding in c++, from a basci c coder)
Re: stl map with two keys
Quote:
Originally Posted by pdk5
I have ScottMayers STL book, but I find it bit advanced..(may be when i started coding in c++, from a basci c coder)
Scott Meyers' "STL book" (i.e., "Effective STL") is aimed at C++ programmers who already have some background in the portion of the standard library derived from the Standard Template Library, but wish to learn more or to avoid possible bad practices. 2kaud's mention of "The C++ Standard Library, Second Edition", on the other hand, is written by Nicolai Josuttis, who wrote that book with both beginners and experienced C++ programmers in mind. It has more comprehensive coverage of the standard library rather than covering only those parts derived from the STL.