2011-01-24 98 views
0


我有以下功能意外分段故障

bool Graph::termination_condition() { 
    for(int i = 0; i < nodes; i++) { 
     // check if any pair of neighbors is using the same color 
     //vector<int> neigh_colors; 
     //for(int idx = 0; idx < degree(node); idx++) { 
      // adjList[node][idx] is the neighbor 
      //if(find(neigh_colors.begin(), neigh_colors.end(), node_obj[adjList[node][idx]].l_color) == neigh_colors.end() ) 
      // // not found, add 
       //neigh_colors.push_back(node_obj[adjList[node][idx]].l_color); 
      //else 
      // return false; 
     //} 
     // check if the color of the node is used 
     //if(find(neigh_colors.begin(), neigh_colors.end(), node_obj[node].l_color) != neigh_colors.end() ) 
     // return false; 
     // check if color of node is in conflict list 
     //if(node_obj[node].tmp_conf_list.size()) 
     // if(find(node_obj[node].tmp_conf_list.begin(), node_obj[node].tmp_conf_list.end(), node_obj[node].l_color) != node_obj[node].tmp_conf_list.end()) 
     //  return false; 
    } 
    return true; 
    // return false; 
} 

,使分段錯誤,每當我把它叫做

void Graph::otherfunction() { 
    if(termination_condition() == true) 
    return 1; 
} 

可能是什麼問題呢?

由於

UPDATE:

int Graph::otherfunction() { 
    if(termination_condition() == true) 
    return 1; 
} 
+0

「節點」在哪裏申報?爲什麼`terminate_condition`中的所有註釋掉的代碼? – 2011-01-24 22:58:00

+3

`otherfunction`甚至不能編譯,你不能``返回1;``void``函數。 – 2011-01-24 22:58:09

回答

3

我的水晶球稱,this指針爲NULL或以其他方式無效,並且nodes是一個成員變量。

0

由於我們提供的信息量很少,我們所能做的只是猜測。

最好的辦法就是用調試器跳進去,找出問題所在。在otherFunction開始處設置斷點應該是一個很好的開始。