【发布时间】:2012-01-14 18:38:45
【问题描述】:
我故意让迭代器的大小超过std::vectorlike,
for (std::vector <Face>::iterator f = face.begin();
f!=face.end()+5;
++f)
{
// here I try to access (*f).P
// note that I added 5 to the face.end()
}
在编译和运行时我都没有遇到任何错误。我怎样才能防止这种情况发生?
【问题讨论】:
-
不要那样做?至于检测,搜索checked iterators。
-
调试版本通常会捕捉到这一点
-
我使用 Release 是因为需要运行时性能。
-
@Shibli:您需要使用 both 配置。一个叫做“Debug”,另一个叫做“Release”是有原因的。在准备好发布之前,您不想放弃额外的调试测试。
-
我以前没想过。它在调试中给出了运行时错误。谢谢。