开发者

Create struct with boost graph

开发者 https://www.devze.com 2023-04-07 00:26 出处:网络
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 > graphNetworkTy

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 = 开发者_JS百科NULL;

infograph->graph = CreateGraphFromDataset3(file);

I get an erro like this:

"Unhandled exception at 0x00ae4b14 graph.exe : 0xC0000005: Access violation reading location 0x00000018."


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?
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号