夏天/isummer

Sun of my life !Talk is cheap, Show me the code! 追风赶月莫停留,平芜尽处是春山~

博客园 首页 新随笔 联系 管理

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)

  程序运行结果正常。

  如下写法同样不妥,需要调整:

    while( currentPNode->x < node->x  &&   NULL != currentPNode )

 

4. 心得

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

  while()条件判断,先进行“成立条件判断”,再进行“假定成立后的条件判断”

 

 

 

 

 

 

 

 

 

 

posted on 2015-12-19 22:46  夏天/isummer  阅读(2212)  评论(0编辑  收藏  举报