码迷,mamicode.com
首页 > 其他好文 > 详细

BUG_vector iterator not dereferencable

时间:2015-12-19 23:06:34      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

1问题: bug提示图下图所示:

  技术分享

2. 分析

   前前后后核实程序没有错误,退后根据bug提示信息

 vector<Point>::iterator itPoint = tempSortedList.begin();

while (itPoint->y >= yLine && itPoint->y < yLine+MOVEUNION && itPoint != tempSortedList.end() )   

  在vector的源文件中

  技术分享

   提示内容的意思是:“vector迭代器不可以去引用操作”。

  但是在while条件判定中添加了:itPoint != tempSortedList.end(),迭代器的到达末尾的判定。

  唯一可能的原因是,当到达末尾后,外部又从新进入whlie条件判定:

  itPoint->y >= yLine && itPoint->y < yLine+MOVEUNION && itPoint != tempSortedList.end()

  但是首先进行的是:itPoint->y,取引用操作,因为此时迭代器指向了tempSortedList.end(),所以抛出此异常

3. 修改

   首先进行迭代器是否到末尾的判定,然后在进行其他迭代器操作,这是基于如果到达末尾迭代器位置,则不进行下述判定。

while (itPoint != tempSortedList.end() && itPoint->y >= yLine && itPoint->y < yLine+MOVEUNION)

  程序运行结果正常。

4. 心得

  写程序要用心考虑,思维缜密,考虑周全!

 

 

BUG_vector iterator not dereferencable

标签:

原文地址:http://www.cnblogs.com/icmzn/p/5059983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!