Non dereferencable iterator C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tonylamb
    New Member
    • Feb 2008
    • 1

    Non dereferencable iterator C++

    Hi All,
    I seem to be getting an error with my code when running Intel C++ compiler via Visual Studio 2005. The error generated is "Expression :map/set iterator not dereferencable"
    I've given my code below in the hope that someone can spot the problem.
    Many Thanks.......

    [code=C++]
    set<stl_index>: :iterator eit1, eit2=elmt_ids.b egin();
    bool non_consecutive (false);

    // 0. checking whether the elements are consecutively numbered
    for ( eit2++, eit1=elmt_ids.b egin(); eit1!=elmt_ids. end(); eit1++, eit2++ )
    if ( (*eit1)+1 != (*eit2) ) {
    non_consecutive =true;
    break; [/code]
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I have no idea why you are getting that error. I took your code and added other code (all assumptions) and got it to compile an link on Visual Studio.NET 2005.

    This is what I compiled:
    [code=cpp]
    struct stl_index
    {
    stl_index operator+(int arg) {stl_index temp; return temp;}
    bool operator!=(stl_ index arg) {return true;}
    };
    set<stl_index> elmt_ids;
    void fx()
    {
    set<stl_index>: :iterator eit1, eit2=elmt_ids.b egin();
    bool non_consecutive (false);

    // 0. checking whether the elements are consecutively numbered
    for ( eit2++, eit1=elmt_ids.b egin(); eit1!=elmt_ids. end(); eit1++, eit2++ )
    {
    if ( (*eit1)+1 != (*eit2) )
    {
    non_consecutive =true;
    break;
    }
    }
    }
    int main()
    {

    }
    [/code]

    Comment

    Working...