我作为最后的手段来到这里 - 我现在绝对没有想法。
我正在修改传统项目中的一些函数模板,将vector作为参数,以便它们通过取代迭代器来遵循STL范例。
当我需要从迭代器中找出返回类型时,我的问题出现了。出于这个目的,我已经实现了以下模板(现在为了找到错误,现在已经剥离了它的最低限度)。
template<class InputIterator>
typename std::iterator_traits<InputIterator>::value_type
foo(InputIterator first, InputIterator last)
{
typedef typename std::iterator_traits<InputIterator>::value_type T;
T out = T();
return out;
}
然后将其称为:
std::vector<float> test (10);
float value = foo(test.begin(), test.end());
,不能编译:
错误2440:无法转换为&#39; float *&#39;到了&#39;浮动&#39;。
据我了解,iterator_traits::value_type
应返回值类型,而不是指针类型。
关于为什么会发生这种情况或者我可能缺少什么的任何想法?不幸的是,这个项目是C ++ 98,所以没有默认的模板参数,decltype
,auto
等。