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

问题描述 投票:2回答:1

这是一个奇怪的,我希望在现有函数中使用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之前包含boost/graph/strong_components.hpp,上面的代码只能在我的系统上编译(Linus,g ++ 8.2.1,Boost 1.67)。使用wandbox,我没有找到没有发生这种情况的编译器/ Boost版本的组合。

我会为此提交一张票,但是Boost使这个不必要地变得困难(我没有Boost's Trac的TICKET_CREATE权利,但是如何获得那些并没有在任何地方指定)。

c++ boost boost-graph
1个回答
1
投票

这里没问题:Live On Coliru

也试试

这让我相信这是你的其他代码/编译器配置的问题。

你在窗户吗?我在max看到windows.h是一个MACRO。一定不要包括(如果你使用它也检查stdafx.h

UPDATE

编辑后,我能够重现错误。这是助推器中的一个错误,我在the bug tracker为它创建了一张票

© www.soinside.com 2019 - 2024. All rights reserved.