c++ - 逻辑错误 : Unable to determine the cause of segmentation fault

标签 c++ 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;

最佳答案

这取决于 ij 的类型 - 如果 ij unsigned,上面的循环会非常愉快地循环回来——这可能是正在发生的事情——打印索引,你会看到……

关于c++ - 逻辑错误 : Unable to determine the cause of segmentation fault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6730943/

相关文章:

c++ - 返回嵌套类的对象

c++ - 当前线程的线程关联掩码更改有什么好处?

c++ - 主窗口关闭时 QWidget 不会关闭

c++ - Opencv Segmentation Fault 使用 pthread 捕获帧 C++

php - 升级Apache和PHP后某个函数导致segmentation fault

c++ - 冒泡排序擅长什么?

c++ - Visual Studio 不会更新 C++ 版本

objective-c - objective-c 代码中的段错误

如果在调用任何函数后调用 gtkfilechooser,C GTK+ 段错误

c++ - 全局 vector 在C++程序结尾导致段错误