iterator->second-VBForums
Results 1 to 2 of 2

Thread: iterator->second

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    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.

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.