【发布时间】:2012-03-06 00:17:46
【问题描述】:
我查看了一些示例,据我所知,我正确使用了拼接方法。但是,当我在 Visual C++ 下以调试模式运行程序时,调用堆栈显示我对 splice 的调用最终到达了崩溃的这一行:
_Mynextiter = _Parent_proxy->_Myfirstiter;
代码:
for(std::list<Rect>::iterator i = rects.begin(); i != rects.end();)
{
if(i->isOverlapping(newRect))
{
Rect oldRect = (*i);
i = rects.erase(i);
std::list<Rect> & lr = oldRect.split(newRect);
//doesn't work either
//rects.splice(rects.begin(), lr, lr.begin(), lr.end());
rects.splice(rects.begin(), lr);
}
else i++;
}
【问题讨论】:
-
好的,所以看起来列表可能无法在循环中拼接。我做了一个不在循环内拼接的实现,但我无法测试它,因为我离开了我的 Windows 机器并且我在 g++ 中得到了完全不同的行为。