|
-
Aug 17th, 2002, 01:34 PM
#1
Thread Starter
Hyperactive Member
iterator->second
i am using a message map for message handling in my win32 window wrapper. i found a reference on the net, and one line has this:
PHP Code:
typedef tyMessageMap::iterator tyMessageIterator;
further on, it does this with the iterator:
PHP Code:
tyMessageIterator it;
(...)
return it->second; //what does this do anyways?
when i try to access the second member with the -> operator it desont' show anything..thats cuz ints not a pointer..i tried the . operator, but the iterator doesn't even have a second member..i looked on the STL doc and it doesn't have that member either..what do i need to use instead?
Amon Ra
The Power of Learning.
-
Aug 17th, 2002, 04:43 PM
#2
That iterator class (std::map<A,B>::iterator) has an overloaded operator -> and operator *
So "it->second" is actualy "it.operator ->()->second"
The operator -> returns a std::pair<A,B>*
A std::pair has a second member which is what you are accessing.
If it returns nothing (what is nothing? Empty string? NULL pointer, 0?) that means that that's the value (first is the key) of that item in the map.
You should also make sure that
it!=name_of_map.end();
which would indicate an error (usualy searched item not found)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|