Vector iterator not dereferencable

前端 未结 3 901
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 09:27

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

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 10:22

    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.

提交回复
热议问题