2
こんにちは。私は次のコードを実行しようとしています(訓練目的のためだけです):'struct std :: iterator_traits <int>'に 'value_type'という名前のC++型がありません
#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>’
最初のテンプレートで何が間違っていますか?私は説明に感謝する以上のものです。
ありがとうございます。時には、最も明白なことは不明です。 – rodrykbyk