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」,它不會有甚至殺入內線,如果。
上述問題的原因是什麼?
EDIT 1:
爲了使問題更清楚,我打印出該語句的兩個條件,並顯示在盯着線的誤差。
的結構是:
typedef struct branch
{
unsigned int distance;
int connectedExitPoint;
} branch;
typedef struct route
{
int exitPoint;
vector <branch> selectedBranchesVector;
} route;
vector <route> routeVector;
它是什麼類型的exitPoint和connectedExitPoint成員? 如果是類,問題可能也在它的operator ==()函數中。 – SKi
@ User1我修改了代碼,參見上文。 –
什麼是i和j的類型?如果這個類型是無符號的並且'routeVector'是空的,那麼'(routeVector.size() - 1)'是肯定的。 – SKi