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.

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;

The only problem I can see with your code is that eit2 will overflow, being one step in front of eit1 each time. I can't see anything which looks like it should give a compiler error. Could you paste a more complete example of your code, since the actual problem may be elsewhere.

Thanks for that Bench. Unfortunately I probably didn't say it clearly enough but my code compiles ok but the problem crops up during debugging.... Since you picked up the overflow of eit2 any ideas on how I can improve my code.....
Once again Thanks for any help you can offer......

In which case, the message may be telling you that you're attempting to de-reference the end() iterator (Which is actually 'one past the end'). To prevent the overflow problem, you might consider changing your loop terminating condition to eit2!=elmt_ids.end() If eit1 is always one step behind eit2, then this check ought to ensure both iterators stay within the boundaries of elmt_ids begin/end range.

edit - fixed BB code tag

Thanks Bench it worked....I know I'm being a pain now but I new error surfaces during debug "Expression: deque subscript out of range" and the debugger points to the following bit of code... stl_index here is type unsignedint32..... I think alot of my problems are cropping up due to my novice status to OOC++

stl_index                  nodes_per_element = plist[0].size();
    deque<vector<stl_index> >::iterator  it;

it would appear that your plist is empty at the point where your debugger has reached that portion of code.

You might prefer to use the deque::at() function, which is bounds checked, and throws an out_of_range exception if you attempt to retrieve something from the deque which doesn't exist.

alternatively, you could check the element you're accessing against the size of plist

if( 0 < plist.size() )
{
    stl_index nodes_per_element = plist[0].size();
    deque<vector<stl_index> >::iterator it;
    //etc.

Thanks again Bench....Sorry it took me a few days to respond. My PhD supervisor uses all the code files that I'm using but on Metrowerks Code Warrior and does not seem to have any issues. He believes I'm having problems becuse the Intel Compiler uses all the microsoft headers...... I'd welcome any comments or suggestions that you might have......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.