-1
我得到下面的代碼段故障:C++分割故障for循環
Node *pointerArray[6];
int onesNeighbor[]={2,3,6};
Node *createNode(int localDistance)//////creates a node
{
Node *newNode;
newNode=new Node;
newNode->wasVisited=false;
newNode->shortestDistance=localDistance;
return newNode;
}
void insertNode(Node *n,int i)//////////////////connects nodes to the
{/////////////////////////////////////////array of pointers
pointerArray[i]=n;
}
for(i=1;i<7;i++)
{
if(i==1){
n=createNode(0);
cout<<i<<"\t"<<n->shortestDistance<<"\t";
for(int j=0;j<=2;j++)
cout<< onesNeighbor[j]<<",";
cout<<endl;
for (count = 1; count < 2; count++)
{
current = pointerArray[count];
if (count == 1)
{
for (int j = 0; j <= 2; j++)
{
lowest = current->shortestDistance;
current = pointerArray[onesNeighbor[j]];
if (current->shortestDistance < lowest)
{
lowest = current->shortestDistance;
closestNeighbor = onesNeighbor[j];
}
}
}
}
請幫助.....
線段故障發生在哪條線上? – TheFuzz 2011-05-03 00:53:23
我們需要看到'pointerArray'和'onesNeighbor'的聲明能夠準確地告訴你,但基本上,其中一個數組要麼太小,要麼是一個野指針 - 可能是後者。 – 2011-05-03 00:53:30
當前寫入的COde永遠不會到達內部循環,因爲在第一次迭代開始時count將爲2。 – Joe 2011-05-03 01:45:23