Boost logo

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,

I’m trying to build a DAG thanks to BGL, the source code builds fine but crashes at runtime. And I’m a bit lost on the reason. I don’t 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 ».

I’ve 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 don’t know if I’m correctly using BGL. I don’t really know what is the proper way (I don’t understand everything from the BGL documentation…). I tried to debug the program but with all those template arguments I don’t understand the error (http://pastebin.com/BRgz3uL7 in case you want to make nightmares :) ).

Thus in case someone understands what’s 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