C++ boost中访问顶点时出现分段错误
我有以下代码:C++ boost中访问顶点时出现分段错误,c++,boost-graph,C++,Boost Graph,我有以下代码: class Translator { typedef property<symbol_t,string,property <message_t,string> > edge_properties; typedef property<vertex_name_t,string, property<vertex_index_t,int,property<vertex_index1_t,bool> > > vertex_prop
class Translator
{
typedef property<symbol_t,string,property <message_t,string> > edge_properties;
typedef property<vertex_name_t,string, property<vertex_index_t,int,property<vertex_index1_t,bool> > > vertex_properties;
typedef adjacency_list<listS,listS,directedS,vertex_properties,edge_properties> Graph;
typedef property_map<Graph,vertex_name_t> :: type name_id ;
typedef graph_traits<Graph>::vertex_descriptor vert_descript;
vector<vert_descript> Process_initial_state;
vector<Graph> Processes;
vector<name_id> Process_state_name;
Translator(const char *path)
{
generate_automata(path);
print_things();
}
void print_things()
{
vert_descript vert;
for(int i=0;i<Process_initial_state.size();i++)
cout<<endl<<Process_state_name[i][Process_initial_state[i]];
}
void generate_automata(const char *path)
{
xml_document xml;
xml_parse_result xml_result = xml.load_file(path);
xml_node temp = xml.first_child();
graph_traits<Graph>::vertex_descriptor vertex;
graph_traits<Graph>::vertex_descriptor from_vertex;
graph_traits<Graph>::vertex_descriptor to_vertex;
for(temp = temp.child("role");temp;temp = temp.next_sibling("role"))
{
//Adding states to the Graph
string role = temp.attribute("name").value();
Graph process;
name_id state_name = get(vertex_name,process);
vert_descript istate;
vector<vert_descript > fstates;
for(xml_node temp1 = temp.child("states").child("state");temp1;temp1 = temp1.next_sibling())
{
string state = temp1.child_value();
state = role + "_" + state;
vertex = add_vertex(process);
state_name[vertex] = state;
if(temp1.attribute("type") && (!strcmp(temp1.attribute("type").value(),"initial")))
{
istate = vertex;
}
if(temp1.attribute("type") && (!strcmp(temp1.attribute("type").value(),"final")))
fstates.push_back(vertex);
}
}
Process_initial_state.push_back(istate);
Process_state_name.push_back(state_name);
}
}
};
类转换器
{
typedef属性边_属性;
typedef属性顶点_属性;
typedef邻接列表图;
typedef属性_映射::type name_id;
typedef图形特征::顶点描述符顶点描述符;
向量过程的初始状态;
向量过程;
向量过程\状态\名称;
转换器(常量字符*路径)
{
生成_自动机(路径);
打印东西();
}
作废打印内容()
{
垂直描述垂直;
对于(int i=0;i我认为变量state_name
是外部for
循环的局部变量。退出循环后,变量被销毁,并且您正在将释放内存的引用放入向量中。如果我正确读取了您的代码,您应该在退出循环之前将state_name
推入向量中。我认为变量state\u name
是外部for
循环的本地变量。退出循环后,变量被销毁,并且您正在将释放内存的引用放入向量中。如果我正确读取了您的代码,您应该在退出循环之前将state\u name
推入向量中我想这是因为内存损坏。内存损坏??我该怎么补救?也许调试可以揭示一些东西。基本上,想法是找到你在哪里写(或读)超出分配的内存并修复它。但是向量本身不应该为内存进行调整吗…我以前从未遇到过向量的sch问题…我也尝试过用int作为向量类型制作这样的dummny程序。它工作正常。我想向量应该工作正常,也许还有其他问题。试着找出导致错误的行。这是哈我想是因为内存损坏而出现的。内存损坏??我该怎么补救呢?也许调试可以揭示一些东西。基本上,想法是找到你写(或读)的地方超出分配的内存并修复它。但是向量本身不应该为内存进行调整…我以前从未遇到过向量的问题…我也尝试过用int作为向量类型制作这样的dummny程序。它工作正常。我想向量应该工作正常,可能还有其他问题。试着找出导致错误的行。