gpt4 book ai didi

c++ - boost::graph add_vertex 编译错误

转载 作者:行者123 更新时间:2023-11-30 01:58:20 25 4
gpt4 key购买 nike

我正在尝试使用 boost::graph header 库,但我仍然无法将 Verticle 添加到我的图表中。

下面是我如何使用 add_vertex 函数:

void GraphManager::addToGraph(VertexProperties node){

//no error, but i do not need it
vertex_t v = boost::add_vertex(graph);

//compilation error
vertex_t v = boost::add_vertex(node, graph);

/*...*/
}

我的定义在这里:

#ifndef GRAPH_DEFINITION_H
#define GRAPH_DEFINITION_H

#include <boost/graph/adjacency_list.hpp>
#include "matchedword.h"

typedef MatchedWord* VertexProperties;

struct EdgeProperties
{
int distance;
EdgeProperties() : distance(0) {}
EdgeProperties(int d) : distance(d) {}
};

struct GraphProperties {

};

typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::undirectedS,
boost::property<VertexProperties, boost::vertex_bundle_t>,
boost::property<EdgeProperties, boost::edge_bundle_t>,
boost::property<GraphProperties, boost::graph_bundle_t>
> Graph;

typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;


#endif // GRAPH_DEFINITION_H

有什么想法吗?谢谢。

error: no matching function for call to 'add_vertex(MatchedWord*&, Graph&)' candidates are: [...] template typename Config::vertex_descriptor boost::add_vertex(const typename Config::vertex_property_type&, boost::adj_list_impl&)

note: template argument deduction/substitution failed:

note: 'Graph {aka boost::adjacency_list, boost::property, boost::property >}' is not derived from 'boost::adj_list_impl'

我不明白这个错误输出的意思。

最佳答案

使用捆绑属性更容易。

像这样:

// A class to hold bundled properties for a vertex
// In this case, we have a pointer to a MatchedWord object

class vertex_props {
public:
MatchedWord * pMW;
};

定义具有捆绑属性的图形类型

typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::undirectedS,
vertex_props,
...
> Graph_t;

现在您可以像这样添加具有指定捆绑属性的顶点

void GraphManager::addToGraph(MatchedWord * node){
graph[ boost::add_vertex(graph) ].pMW = node;
...

关于c++ - boost::graph add_vertex 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17595949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com