我想使用我用图表创建的这个结构:
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;
但是当我试图使用函数构建图形时:
INFOGRAPH *infograph = NULL;
infograph->graph = CreateGraphFromDataset3(file);
我得到一个像这样的错误:
"Unhandled exception at 0x00ae4b14 graph.exe : 0xC0000005: Access violation reading location 0x00000018."
答案 0 :(得分:1)
我怀疑这甚至可以编译,因为你的INFOGRAPH
课程甚至没有拥有名为graph
的成员。
更重要的是,你从未创建过该类的实例 - 你只是创建了一个指针,将其设置为NULL并取消引用它。当然这是无效的,让你崩溃。
您可以自动或动态创建实例,具体取决于您将如何使用它:
// Automatic:
INFOGRAPH infograph;
infograph.graph = CreateGraphFromDataset3(file);
// Dynamic:
INFOGRAPH * pinfograph = new INFOGRAPH;
pinfograph->graph = CreateGraphFromDataset3(file);
// ouch, who cleans up `*pinfograph` now?