私はExを実行しようとしています。 10-02のAccelerated C++で、私にエラーを与えていたので、私はこの時点まで私のプログラムを "簡素化"していましたが、それでもエラーはg ++でコンパイルされませんでした:イテレータを使用したテンプレート関数
test.cpp: In function ‘int main()’:
test.cpp:22: error: no matching function for call to ‘dumb(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >)’
ここに私のプログラムです:
#include <algorithm>
#include <iostream>
#include <vector>
using std::cout; using std::endl;
using std::vector;
template <class Ran, class T> T dumb(Ran begin, Ran end)
{
return *begin;
}
int main()
{
vector<int> myVector;
for (int i = 1; i <= 9; ++i)
myVector.push_back(i);
int d = dumb(myVector.begin(), myVector.end());
cout << "Value = " << d << endl;
return 0;
}
このエラーの原因は何?
+1それに私を殴る、ひどい... – hmjd
+1、この答えは、そのような容器に対処するより簡単で正しい方法です。 – iammilind
ああ、いいです..私の本はまだIndex_typeの使用をカバーしていませんが、私はIndexを見ていますが、次の章にあります。 – adelbertc