我有以下几行代码和编译错误。应该是我对模板函数的错误理解,或者c++泛型,或者别的什么。提前感谢您指出。
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
T* find(vector<T> &vec, T value)
{
vector<T>::iterator first = vec.begin();
vector<T>::iterator last = vec.end();
for(; first != last; first ++)
if(*first == value)
return first;
return 0;
}
控制台中的编译错误
debug.cpp: In function ‘T* find(std::vector<T, std::allocator<_CharT> >&, T)’:
debug.cpp:9: error: expected `;' before ‘first’
debug.cpp:10: error: expected `;' before ‘last’
debug.cpp:11: error: ‘first’ was not declared in this scope
debug.cpp:11: error: ‘last’ was not declared in this scope