unsigned int j   = 0;
    openListIterator = openListVector.begin ();
    while (exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].connectedExitPoint >= openListVector[j].pointId)
           && (openListIterator <= openListVector.end()))
    {
        // Move the iterator.
        openListIterator++;
        // Move the index.
        j++;
    }

    // Insert in the vector in the required position.
    listStruct objOpenListStruct;
    objOpenListStruct.pointId       = exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].connectedExitPoint;
    objOpenListStruct.weight        = exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].weight + exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].distance;
    objOpenListStruct.parentPointId = exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].exitPoint;

    ***********openListVector.insert (openListIterator, objOpenListStruct);


此代码在for循环下。
但是我将正确的迭代器初始化放在加星号的行上,但仍然遇到分段错误。

有什么提示吗?

最佳答案

在语句openListIterator <= openListVector.end()中,如果达到openListIterator == openListVector.end(),则将出现段错误,因为当代码达到openListIterator++时,迭代器将变得“越界”

尝试openListIterator != openListVector.end()

09-08 01:01