这是一个奇怪的,我希望在现有函数中使用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
权利,但是如何获得那些并没有在任何地方指定)。
这里没问题:Live On Coliru
也试试
- https://wandbox.org/permlink/jDIYB9oCjAP2wxHo wandbox,它允许您切换编译器版本,标志和每个可能的升级版本
这让我相信这是你的其他代码/编译器配置的问题。
你在窗户吗?我在max
看到windows.h
是一个MACRO。一定不要包括(如果你使用它也检查stdafx.h
)
编辑后,我能够重现错误。这是助推器中的一个错误,我在the bug tracker为它创建了一张票