使用 boost graph 创建结构体

发布于 2024-12-06 04:33:50 字数 653 浏览 1 评论 0原文

我想使用我用图形创建的结构:

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."

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."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-12-13 04:33:50

我怀疑这是否可以编译,因为您的 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?

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?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文