BGL:当包含random_spanning_tree.hpp时,对strong_components的调用无法编译

时间:2018-09-08 22:11:27

标签: c++ boost boost-graph

这是一个很奇怪的问题,我希望在现有函数中使用boost::random_spanning_tree,该函数也调用boost::strong_components,但是仅包含boost/graph/random_spanning_tree.hpp而不修改代码会使gcc产生编译错误。

函数看起来像这样:

#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/strong_components.hpp"                                    
//#include "boost/graph/random_spanning_tree.hpp" // can't include this!

void foo() {
  boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> g;

  // TODO: add some vertices

  std::vector<unsigned> component(boost::num_vertices(g));
  unsigned num = boost::strong_components(g, &component[0]);
}

和gcc抱怨:

error: no matching function for call to ‘get(unsigned int*&, boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> >::vertex_descriptor&)’
           if (get(comp, w) == (std::numeric_limits<comp_type>::max)())

代码本身有缺陷还是Boost的问题?

编辑:

我很抱歉,在我的最小示例中,我犯了一个小错误,如果包含boost/graph/random_spanning_tree.hpp,则上面的代码只能在我的系统(Linus,g ++ 8.2.1,Boost 1.67)上无法编译。 boost/graph/strong_components.hpp之前。使用wandbox,我发现没有编译器/ Boost版本的组合不会发生。

我为此准备了入场券,但是Boost使这不必要地变得困难(我没有TICKET_CREATE权利给Boost的Trac,但如何获得这些的权利在任何地方都没有指定)。

1 个答案:

答案 0 :(得分:1)

这没问题: Live On Coliru

  

也尝试

     

这使我相信其余的代码/编译器配置有问题。

您在Windows上吗?我看到maxwindows.h中的宏。确保不包括该内容(如果使用,请检查stdafx.h

更新

编辑后,我可以重现该错误。那是提升的一个错误,我已经在the bug tracker

为其创建了一个票证