Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non dereferencable iterator C++

Status
Not open for further replies.

tonylamb2003

Programmer
Feb 9, 2008
1
GB
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.

Code:
    set<stl_index>::iterator  eit1, eit2=elmt_ids.begin();
    bool                               non_consecutive(false);
    
    // 0. checking whether the elements are consecutively numbered
    for ( eit2++, eit1=elmt_ids.begin(); eit1!=elmt_ids.end(); eit1++, eit2++ )
      if ( (*eit1)+1 != (*eit2) ) {
           non_consecutive=true;
      break;
 
I have no idea what stl_index is, but you're missing some braces.
This code compiles fine on Comeau:
Code:
#include <set>
using namespace std;
typedef int  stl_index;

int main()
{
   set<stl_index> elmt_ids;

   set<stl_index>::iterator  eit1, eit2=elmt_ids.begin();
   bool non_consecutive = false;
    
   // 0. checking whether the elements are consecutively numbered
   for ( eit2++, eit1=elmt_ids.begin(); eit1!=elmt_ids.end(); eit1++, eit2++ )
   {
      if ( (*eit1)+1 != (*eit2) )
      {
         non_consecutive = true;
         break; 
      }
   }

   if ( non_consecutive )
      return 0;
   else
      return 1;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top