C++ 意外分段错误
C++ 意外分段错误,c++,segmentation-fault,C++,Segmentation Fault,我有以下功能 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++)
我有以下功能
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;
}
有什么问题吗
谢谢
更新:
int Graph::otherfunction() {
if( termination_condition() == true )
return 1;
}
我的水晶球说,
这个
指针为空或无效,节点
是一个成员变量。我的水晶球说,这个
指针为空或无效,节点
是一个成员变量。我们得到的信息很少,我们所能做的就是猜测
最好的办法是使用调试器跳入其中,找出问题所在。在
otherFunction
的开头设置一个断点应该是一个很好的开始。我们得到的信息很少,我们所能做的就是猜测
最好的办法是使用调试器跳入其中,找出问题所在。在
otherFunction
的开头设置断点应该是一个很好的开始。在哪里声明了节点?为什么termination\u条件中所有注释掉的代码
?otherfunction
甚至不会编译,您不能返回1从void
函数中选择code>。@Charles:注释掉大量代码是缩小崩溃发生位置的合理方法。而且,if(…==true)
真是愚蠢。没有人会期望分段错误!它的主要武器是惊喜。。。惊讶和恐惧…恐惧和惊讶。它的两个武器是恐惧和惊讶…和无情的效率。。。。它的三种武器是……节点在哪里?为什么termination\u条件中所有注释掉的代码
?otherfunction
甚至不会编译,您不能返回1从void
函数中选择code>。@Charles:注释掉大量代码是缩小崩溃发生位置的合理方法。而且,if(…==true)
真是愚蠢。没有人会期望分段错误!它的主要武器是惊喜。。。惊讶和恐惧…恐惧和惊讶。它的两个武器是恐惧和惊讶…和无情的效率。。。。它的三种武器是……我不知道。如果他在其他一些例程中对堆栈进行了大量操作,而堆栈在那里崩溃了,那么调试人员可能帮不了什么忙。没错,但如果他在那里,并且所有数据都被破坏了,他就会知道去别处找。良好的起点。:)我不知道。如果他在其他一些例程中对堆栈进行了大量操作,而堆栈在那里崩溃了,那么调试人员可能帮不了什么忙。没错,但如果他在那里,并且所有数据都被破坏了,他就会知道去别处找。良好的起点。:)
int Graph::otherfunction() {
if( termination_condition() == true )
return 1;
}