An iterator point to nowhere?

I defined the following function to find out the iterator of a certain value in the vector. I defined it as such so if the value exist in the vector then return a iterator of it, if not then return a pointer pointing to nonsense.:

vector<tIndex_t>::iterator unlabelTit(const tIndex_t index) {
	for(vector<tIndex_t>::iterator it=unlabelT.begin(); it<unlabelT.end(); it++) {
		if(index==*it) return it;
    return NULL;

But looks this one is not accepted by compiler, saying I cannot do this kind of comparison like:


so I just delete the return NULL; and then the compiler giving me warning about no return statement before }.

a pointer pointing to nonsense? how to do that?
I'd say the proper behavior is to return an iterator pointing to end() (1 past the end of the container, and thus it is invalid in all cases); this is what all standard find functions do, and what it looks like you are trying to to with your function.
Iterators are not comparable to NULL like pointers. STL algorithms return Container.end() instead.
Topic archived. No new replies allowed.