【发布时间】:2012-01-20 01:26:17
【问题描述】:
我一直在尝试做 Ex。 10-02 in 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;
}
是什么导致了这个错误?
【问题讨论】:
标签: c++ templates compiler-errors iterator