【发布时间】:2015-05-17 18:56:04
【问题描述】:
我正在尝试为函子的参数定义默认值。但是我收到了这个错误:
注意:候选模板被忽略:无法推断模板参数 '比较'
这是我的函数的定义:
template <typename RAIterator, typename Comp>
void somefunction(RAIterator beg, RAIterator end, Comp comp=
[](const typename iterator_traits<RAIterator>::value_type& a,
const typename iterator_traits<RAIterator>::value_type& b)->bool
{return b<a?true:false;}){
//the content of the "somefunction"
}
我想知道我是否可以这样做,如果可以,我做错了哪一部分。谢谢。
【问题讨论】:
-
我认为您不能从默认参数中进行模板参数推导。您首先需要知道模板参数,然后才能实例化函数模板,包括其默认参数。
标签: c++ lambda functor default-arguments