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;
}
编译出错,提示,参数类型嵌套依靠类型。
那我该怎么改?
奇怪的是在vc++6.0下能通过,连警告都没有!
这样修改下看看行不行.
template<class T>
typename vector<T>::iterator find(typename vector<T>::iterator fir,typename vector<T>::iterator sec,
const T &key){
for (;fir != sec;++fir){
if (*fir == key)
return fir;
}
return sec;
}
#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;
}