Boost图库:性病::名单VertexList时,模板参数 [英] Boost Graph Library: std::list as VertexList template parameter

查看:83
本文介绍了Boost图库:性病::名单VertexList时,模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打造代替的std ::矢量的std ::名单顶点的图$ C>。

I'm trying to build a graph with vertices stored in a std::list instead of a std::vector.

不过我被一个编译错误,我得到混淆。最小code,我用的就是

However I am confused by a compilation error I get. The minimal code I'm using is

#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]

这似乎在抱怨从 INT 的无效​​转化为无效*

that seems complaining about an invalid conversion from int to void*.

但是,如果我更改列出血管内皮细胞一切工作正常。

However if I change listS to vecS everything works fine

#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;
}

我在想什么?是不是顶点应该是没有code的休息吗?

What am I missing? Isn't the container of vertices supposed to be interchangeable without further modification of the rest of the code?

推荐答案

随着人们说,你不能在列表支持图形中的节点用0或1。这将工作虽然:

As people have said, you can't use 0, or 1 for a node in a list backed graph. This will work though:

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);

您需要做一个顶点的补充。
有code在<一一些有用的位href=\"http://stackoverflow.com/questions/7156880/dijkstra-shortest-path-with-vertexlist-lists-in-boost-graph\">this问题

You need to make a vertex to add. There are some helpful bits of code in this question

这篇关于Boost图库:性病::名单VertexList时,模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆