Create struct with boost graph

0

I whant to use this structure that I've created with a graph:

typedef struct type_INFOGRAPH
{
    boost::adjacency_list < boost::listS, boost::vecS, boost::undirectedS, Node, Line > graphNetworkType;

    map<int,graph_traits<graphNetworkType>::edge_descriptor> emymap;

    map<int, graph_traits<graphNetworkType>::vertex_descriptor> vmymap;

}INFOGRAPH;

But when I trie to construct the graph with a function:

INFOGRAPH *infograph = NULL;

infograph->graph = CreateGraphFromDataset3(file);

I get an erro like this:

"Unhandled exception at 0x00ae4b14 graph.exe : 0xC0000005: Access violation reading location 0x00000018."
c++
boost
graph
struct
asked on Stack Overflow Sep 22, 2011 by user923838 • edited Sep 22, 2011 by Kerrek SB

1 Answer

1

I doubt this even compiles, since your INFOGRAPH class doesn't even have a member called graph.

More importantly, though, you've never created an instance of the class - you just made a pointer, set that to NULL and dereferenced it. Naturally that isn't valid and gets you crashed.

You can make an instance either automatically or dynamically, depending on how you're going to use it:

// Automatic:
INFOGRAPH infograph;
infograph.graph = CreateGraphFromDataset3(file);

// Dynamic:
INFOGRAPH * pinfograph = new INFOGRAPH;
pinfograph->graph = CreateGraphFromDataset3(file);
// ouch, who cleans up `*pinfograph` now?
answered on Stack Overflow Sep 22, 2011 by Kerrek SB

User contributions licensed under CC BY-SA 3.0