逻辑错误:无法确定分割错误的原因
Logical error: Unable to determine the cause of segmentation fault
for (i = (routeVector.size () - 1); i >= 0; i--)
{
cout << "Connected to -> " << routeVector[i].exitPoint;
for (j = (routeVector.size () - 1); j >= 0; j--)
{
if (routeVector[i].selectedBranchesVector.size() > 0)
{
cout << "n: routeVector[i].selectedBranchesVector[0].connectedExitPoint" <<
routeVector[i].selectedBranchesVector[0].connectedExitPoint;
******cout << "nrouteVector[j].exitPoint:" << routeVector[j].exitPoint;
if (routeVector[i].selectedBranchesVector[0].connectedExitPoint == routeVector[j].exitPoint)
{
cout << "Connected to -> " << routeVector[i].selectedBranchesVector[0].connectedExitPoint;
}
}
}
}
起始行给了我分割错误,我不明白为什么。
如果"routeVector"在"selectedBranchesVector"中没有任何内容,它甚至不会到达内部If。
造成上述问题的原因是什么?
编辑1:
为了使问题更清楚,我打印了语句的两个条件,错误显示在开始的行上。
结构为:
typedef struct branch
{
unsigned int distance;
int connectedExitPoint;
} branch;
typedef struct route
{
int exitPoint;
vector <branch> selectedBranchesVector;
} route;
vector <route> routeVector;
这取决于i
和j
的类型-如果i
和j
是unsigned
,上述循环将非常愉快地循环回来-这可能就是正在发生的事情-打印索引,您将看到…
相关文章:
- C++映射分割错误(核心转储)
- 由cin中的字符串中未捕获空白引起的分割错误
- 删除映射和分割错误中的一个过去结束元素
- 在指向函数中读取变量时出现分割错误
- 在链表中的第 n 位插入显示分割错误
- 较高值 n 的分割错误(例如 n=999997)
- 尝试通过memcpy复制大尺寸浮点向量时的分割错误
- 分割错误:向量中的擦除功能
- 向量向量的分割错误
- 我在C++中编写了一个方法来打印树类的预序,但它显示了分割错误
- C ++分割错误,为什么使用"long long"我没有得到答案?
- 在尝试使用递归查找集合子集的总数时,我遇到了分割错误
- 分割错误 11:尝试使用 cin 输入 B[1] 时
- 集合布局上的 Qt 分割错误
- 高达20亿的筛子会产生分割错误
- G :内部编译器错误:分割故障(程序CC1PLUS) - 我在哪里开始
- 二进制搜索树操作程序错误:分割故障(核心倾倒)
- 在给出正确的输出后,给出错误分割错误(核心转储)
- 得到错误分割错误(核心转储)进程返回139 (0x8B)
- 内部编译错误:分割错误在gcc.发送可变模板到struct时