回复:(aipb2007)[求助]模版函数出问题了!
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template<class T>
typename vector<T>::iterator find(vector<T>::iterator fir,vector<T>::iterator sec,
const T &key){
for (;fir != sec;++fir){
if (*fir == key)
return fir;
}
return sec;
}
int main(){
vector<int> ivec;
int temp;
while (cin >> temp)
ivec.push_back(temp);
vector<int>::iterator p = find(ivec.begin(),ivec.end(),100);
cout << *p << endl;
system("pause");
return 0;
}
f:\practise for vc++2005\practise\practise\prac.cpp(7) : warning C4346: 'std::vector<T>::iterator' : dependent name is not a type
prefix with 'typename' to indicate a type
f:\practise for vc++2005\practise\practise\prac.cpp(7) : error C2146: syntax error : missing ')' before identifier 'fir'
f:\practise for vc++2005\practise\practise\prac.cpp(8) : error C2059: syntax error : ')'
f:\practise for vc++2005\practise\practise\prac.cpp(16) : error C2143: syntax error : missing ';' before '{'
f:\practise for vc++2005\practise\practise\prac.cpp(16) : error C2447: '{' : missing function header (old-style formal list?)
Build log was saved at "
file://f:\practise for vc++2005\practise\practise\Debug\BuildLog.htm"
practise - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========