C++ 在"struct std::iterator_traits"中没有名为"value_type"的类型<int>
C++ no type named ‘value_type’ in ‘struct std::iterator_traits<int>'
你好。我正在尝试运行以下代码(仅出于培训目的(:
#include<iostream>
#include <list>
template<class T,
template<class ,class=std::allocator<T> >class kont >
typename std::iterator_traits<T>::value_type foo_test(typename kont<T>::iterator b){return *b;}
template <class Iter>
typename std::iterator_traits<Iter>::value_type minimum(Iter b, Iter e)
{
Iter m = b;
/*
CODE
*/
return *m;
}
int main(void){
std::list<int> x;
x.push_back(10);
x.push_back(100);
std::cout <<minimum(x.begin(),x.end());
//std::cout <<foo_test<int,std::list>(x.begin());
}
功能最低工作正常,没有问题。但是,当我不按文章的话输入时,我会收到以下错误:
main.cpp:33:50: error: no matching function for call to ‘foo_test(std::__cxx11::list<int>::iterator)’
std::cout <<foo_test<int,std::list>(x.begin());
main.cpp:7:46: note: template argument deduction/substitution failed:
main.cpp:33:50: required from here
main.cpp:7:46: error: no type named ‘value_type’ in ‘struct std::iterator_traits<int>’
那是第一个模板怎么了?我将非常感谢解释。
您将int
作为第一个模板参数T
。因此,std::iterator_traits<T>::value_type
是std::iterator_traits<int>::value_type
,这是不正确的。你的意思是
typename std::iterator_traits<typename kont<T>::iterator>::value_type
。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 在 QVector<std::unique_ptr 上使用 std::find<Type>>
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 控制到达非空函数clang(-Wreturn-type)的末尾
- 为什么我会" void value not ignored as it ought to be"?
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 方法错误"not all control paths return a value"和方法不返回值
- 将系数存储在头文件的数组中("does not name a type"错误)
- 尝试打开 ifstream 时出现"Incomplete type"错误
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 在"结构提升::enable_if<提升::is_pod<T>,无效>"中没有名为"type"的类型
- 如何修复" State Error (active) E0513 a value of type "const wchar_t *" cannot be assigned to an entity o
- "a value of type " void (exeCallback::*)(int) " cannot be assigned to an entity of type " void (*)(
- cmake -D <var>:<type>=<value> 参数"-D"是什么意思
- 没有用于初始化'value type'的匹配构造函数
- new(size, value) Type[0]返回的指针是否合法,是否可以用来构建数组?