2011-01-24 93 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开始处设置断点应该是一个很好的开始。