int the_post = 0;
for (t_peers::iterator i = m_peers.begin(); i != m_peers.end(); ++the_post)
{
    TRACE1("the_post %d\n",the_post);
if (i->post_select(fd_read_set, fd_write_set, fd_except_set))
{
     i->Close();
     i = m_peers.erase(i);
}
else
      ++i;
}
我是跟踪测这段代码的时候总是发现程序在乱跳,并不按照我们想象的步骤走,请问高手是什么原因?例如本来m_peers.size() = 100时,当它走到第20个的时候,突然跳到the_post = 50去。

解决方案 »

  1.   

    不会STL的就不用回答了。谢谢参与!!
      

  2.   

    ...
    i = m_peers.erase(i);
    ......
    ++i;
    ...
    你一直在改变这个循环子????
    不变才怪!
      

  3.   

    能不能请大家看清楚了再说啊?m_peers是个列表,我现在只是用the_post来测它是怎么走的而已。例如我在post_select函数里也TRACE了一个东西出来,有时候the_post都TRACE出来了,但是函数里的东西却没有TRACE出来,然后the_post突然跳了很远,而不是连续的了。
      

  4.   

    改成while or do-while.for语句不同的语言有些不同的细微差别,而while基本没有。
      

  5.   

    看不出来。The_post 我应该是递增的
      

  6.   

    一般,
    Clear
    ReBuilt All
    就可以了。
      

  7.   


    同意楼上,如果很明显的乱跳,ReBuilt All
      

  8.   

    回eastsun() :
      已经试过,问题是一样的!!!