2

我正在尝试使用存储在 astd::list而不是 a中的顶点构建一个图形std::vector

但是,我对收到的编译错误感到困惑。我正在使用的最小代码是

#include <boost/graph/adjacency_list.hpp>

using namespace boost;

int main() {

  typedef adjacency_list< listS,listS > Graph;

  Graph g;

  add_edge(0,1,g);

  return 0;
}

编译时gcc-4.7.3出现以下错误:

/Users/matteo/Documents/workspace/graph-gravity-dec/src/test.cpp: In function 'int main()':
/Users/matteo/Documents/workspace/graph-gravity-dec/src/test.cpp:12:17: error: invalid conversion from 'int' to 'boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, boost::listS>, boost::listS, boost::listS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>::config::vertex_descriptor {aka void*}' [-fpermissive]
In file included from /opt/local/include/boost/graph/adjacency_list.hpp:246:0,
             from /Users/matteo/Documents/workspace/graph-gravity-dec/src/test.cpp:2:
/opt/local/include/boost/graph/detail/adjacency_list.hpp:681:5: error:   initializing argument 2 of 'std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, boost::directed_graph_helper<Config>&) [with Config = boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, boost::listS>, boost::listS, boost::listS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>::config; typename Config::edge_descriptor = boost::detail::edge_desc_impl<boost::directed_tag, void*>; typename Config::vertex_descriptor = void*]' [-fpermissive]

这似乎在抱怨从intto的无效转换void*

但是,如果我更改listSvecS一切正常

#include <boost/graph/adjacency_list.hpp>

using namespace boost;

int main() {

  typedef adjacency_list< listS, vecS > Graph;

  Graph g;

  add_edge(0,1,g);

  return 0;
}

我错过了什么?如果不进一步修改其余代码,顶点容器难道不应该是可互换的吗?

4

1 回答 1

4

正如人们所说,您不能将 0 或 1 用于列表支持图中的节点。不过,这将起作用:

typedef adjacency_list< listS,listS > Graph;
Graph g;
typedef boost::graph_traits < Graph >::vertex_descriptor Vertex;
Vertex v0 = boost::add_vertex(g);
Vertex v1 = boost::add_vertex(g);
boost::add_edge(v0, v1, g);

您需要创建一个要添加的顶点。这个问题中有一些有用的代码

于 2013-05-30T11:30:15.033 回答