候选模板被忽略:推断的类型与调整后的类型不匹配
Candidate template ignored: deduced type does not match adjusted type
boost 图库中remove_edge
的函数调用存在一个非常奇怪的问题。
当我在 main 函数中调用它时,编译和运行时都可以; 但是当我在模板函数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;
}
编译错误消息:
忽略候选模板:推导类型
'undirected_graph_helper>, boost::no_property, boost::listS>, boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, 提升::p罗珀蒂>, boost::no_property, boost::listS>::config> &'
的第二个参数与调整后的类型不匹配
'常量提升::adjacency_list>, boost::no_property, boost::listS>'
的参数 [与边缘Oriter = 提升::d尾::edge_desc_impl, 配置 = 提升::d尾::adj_list_gen>, boost::no_property, boost::listS>, boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, 提升::p罗珀蒂>, boost::no_property, boost::listS>::config]
我确信编译器为这两种情况选择了相同的重载函数remove_edge
(Xcode 告诉我)。我也知道调用remove_edge
时参数类型是相同的,通过检查typeid(T).name()的输出。
感到绝望,非常感谢任何帮助!
>remove_edge
修改图形,因此不能在常量引用上调用它。最简单的解决方法:
template <typename Graph> void test_remove_edge(Graph& g) {
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 为char数组调整zlib-zpipe
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 具有调整对齐方式的类型定义
- 候选模板被忽略:推断的类型与调整后的类型不匹配
- 调整图像类型"垫子"的大小 opencv C++
- Buit矩形(我自己的类型),不会随窗口调整大小
- magik++api中用于调整大小的默认过滤器类型
- 无法调整类型为template的堆栈的大小
- 针对不同数据类型的单一结构调整方法
- 为什么没有未调整大小的Integer类型
- 在将uint64_t类型转换为double类型时调整精度