CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #1
    Join Date
    Oct 2002
    Posts
    1,134

    STL Map Iteration Question

    I have an STL map that uses a structure as a key:
    Code:
    typedef struct _RC_ {
      UINT  R;
      UINT  C;
    } RC;
    
    typedef struct _Data_ {
      int  data1;
      int  data2;
    } DATA;
     
    struct _RC_Compare {
      bool operator() ( const RC p1, const RC p2 ) const
      {
        return p1.R == p2.R? p1.C < p2.C : p1.R < p2.R;
      }
    typedef std::map< RC, DATA, _RC_Compare >  MY_MAP
    I want to access every member of the map without regard to the key value, so I tried:
    Code:
    MY_MAP::iterator  it;
    for( it = MY_MAP.begin(); it != MY_MAP.end(); ++it )
    {
      // Bunch of code having nothing to do with the map
    }
    When this executes, it termiantes with the message "map/set iterator not incrementable" when it tries to execute the "++it".

    Why can't I sequentially access a map? Everything I've read indicates this is possible, although all the examples have C++ primitives as keys.
    Last edited by TSYS; March 31st, 2009 at 08:15 AM. Reason: Fixed typo
    Regards
    Robert Thompson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured