|
Boost Users : |
Subject: [Boost-users] [Boost.Graph] How to build a directed graph
From: Lucas Soltic (lucas.soltic_at_[hidden])
Date: 2014-01-10 08:59:44
Hello,
Im trying to build a DAG thanks to BGL, the source code builds fine but crashes at runtime. And Im a bit lost on the reason. I dont even know if my typedefs are correct according to my purpose: simply building a DAG whose nodes are « Classes » with arcs that point to « parents ».
Ive written the following:
#include <list>
#include <boost/graph/directed_graph.hpp>
class MyClass {};
typedef MyClass* Vertex;
typedef std::pair<Vertex, Vertex> Edge;
typedef boost::directed_graph<Vertex, Edge> ClassInheritanceGraph;
static ClassInheritanceGraph g_parentClassGraph;
void buildGraph(void)
{
std::list<Edge> edges;
edges.push_back(std::make_pair(new MyClass, new MyClass));
edges.push_back(std::make_pair(new MyClass, new MyClass));
std::list<Edge>::iterator edgesIt;
for (edgesIt = edges.begin(); edgesIt != edges.end(); edgesIt++)
{
Vertex child = edgesIt->first;
Vertex parent = edgesIt->second;
boost::add_edge(child, parent, g_parentClassGraph);
}
}
int main()
{
buildGraph();
return 0;
}
The program crashes on boost::add_edge() with a segfault. The point is I dont know if Im correctly using BGL. I dont really know what is the proper way (I dont understand everything from the BGL documentation
). I tried to debug the program but with all those template arguments I dont understand the error (http://pastebin.com/BRgz3uL7 in case you want to make nightmares :) ).
Thus in case someone understands whats wrong here I would be really grateful for some help!
Thanks,
Lucas
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net