Vector iterator not dereferencable

c++, stl

Solution

Simple :

- find fails since your newly created Circle can't be found in the vector with comparing Shape *

- a failed find returns the end iterator which is not deferencable as caught by a Debug assertion

For it to work like you want, you do need to compare Shape, not Shape*

As pointed out in other answers, boost::ptr_vector is an easy way to achieve this.

Problem

I have an abstract base class called Shape from which both Circle and Rectangle are derived, but when I execute the following code in VS 2005 I get the error Debug assertion failed. At the same time I have not overloaded == operator in any class Expression:Vector iterator not dereferencable, what is the reason for this. ``` vector<Shape*> s1; s1.push_back(new Circle(point(1,2),3)); s1.push_back(new Circle(point(4,3),5)); s1.push_back(new Rectangle(point(1,1),4,5)); vector<Shape*> s2(s1); reverse(s1.begin(),s1.end()); (*find(s1.begin(),s1.end(),new Circle(point(1,2),3)))->move(point(10,20)); ```

Original source