Re: STL list code fires assertion in VC++ 2005, but not in VC++ 2003.
Jason Doucette wrote:
No, the STL is probably the same. But the implementation in VS might
have changed. Consider yourself lucky this probably means you have
uncovered a hidden bug in your code. By the way, what do you mean
with the iterator being checked against NULL? Who did the check?
I have a function that checks a list for some data, by iterating
through it. If it finds the element, it returns the iterator to it.
If not, it returns NULL. The caller of this function checks the
return value (an iterator) to see if it's NULL or not. (Kind of like
a pointer, it either points to something, or NULL...)
std::list<myStruct> myList;
std::list<myStruct>::iterator myIterator;
for (myIterator = myList.begin(); myIterator != myList.end();
myIterator++)
{
if (myIterator != NULL) <----- BANG!
}
This code isn't even remotely close to the real code, Jason. There
is no "function", there is no "caller"...
Does the caller have access to the list? If he does, returning the
'end()' is much better than relying on the iterator's comparability
with NULL. It he does not, why does it have to be an iterator? Make
your function return a pointer, to the contained element if success
and NULL if not.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask