gpt4 book ai didi

c++ - 候选模板被忽略 : deduced type does not match adjusted type

转载 作者:行者123 更新时间:2023-11-28 04:50:05 24 4
gpt4 key购买 nike

<分区>

boost图库中remove_edge的函数调用有一个很奇怪的问题。

当我在主函数中调用它时,编译和运行时都可以;但是,当我在模板函数 test_remove_edge 中调用它时,出现编译错误。

代码示例和编译错误消息在这里。

#include <iostream>
#include <vector>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/max_cardinality_matching.hpp>
#include <boost/graph/maximum_weighted_matching.hpp>

using namespace boost;

template <typename Graph>
void test_remove_edge(const Graph& g)
{
typedef typename graph_traits<Graph>::edge_iterator edge_iterator_t;

edge_iterator_t ei, ei_end;
for (boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei)
{
std::cout << typeid(*ei).name() << ", " << typeid(g).name() << std::endl; // exactly same with the one in main
remove_edge(*ei, g); // compile error, see message pasted below
}
}

int main(int argc, const char * argv[])
{
typedef property<edge_weight_t, float, property<edge_index_t, int>> EdgeProperty;
typedef adjacency_list<vecS, vecS, undirectedS, no_property, EdgeProperty> my_graph;

const int n_vertices = 8;

my_graph g(n_vertices);

add_edge(1,2,EdgeProperty(5),g);
add_edge(0,4,EdgeProperty(1),g);
add_edge(1,5,EdgeProperty(4),g);
add_edge(2,6,EdgeProperty(1),g);
add_edge(3,7,EdgeProperty(4),g);

typedef typename graph_traits<my_graph>::edge_iterator edge_iterator_t;
edge_iterator_t ei, ei_end;
for (boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei)
{
std::cout << typeid(*ei).name() << ", " << typeid(g).name() << std::endl; // exactly same with the one in test_remove_edge
remove_edge(*ei, g); // compile ok, runtime ok
}

test_remove_edge(g);

return 0;
}

编译错误信息:

Candidate template ignored: deduced type

'undirected_graph_helper >, boost::no_property, boost::listS>, boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property >, boost::no_property, boost::listS>::config> &'

of 2nd parameter does not match adjusted type

'const boost::adjacency_list >, boost::no_property, boost::listS>'

of argument [with EdgeOrIter = boost::detail::edge_desc_impl, Config = boost::detail::adj_list_gen >, boost::no_property, boost::listS>, boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property >, boost::no_property, boost::listS>::config]

我确信编译器会为这两种情况选择相同的重载函数 remove_edge(Xcode 告诉我)。我还知道调用 remove_edge 时参数类型是相同的,通过检查 typeid(T).name() 的输出。

感到绝望,非常感谢任何帮助!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com