我正在尝试使用存储在 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]
这似乎在抱怨从int
to的无效转换void*
。
但是,如果我更改listS
为vecS
一切正常
#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;
}
我错过了什么?如果不进一步修改其余代码,顶点容器难道不应该是可互换的吗?