W
wuych
I have a question about using iterator in template function
//*****code starts here*****************************
#include <vector>
using std::vector;
template<typename T> void foo( vector<T> & a )
{
vector<T>::iterator i; // ERROR, can't use iterator
}
int main()
{
vector<int> a;
foo(a);
}
//******code ends here ****************************
//****** compiler: gcc 4.1.3 ************************
Can anyone tell me why it's not allowed to use the iterator this way?
Maybe the best way is to use Iterator directly as STL does.
template<typename Iter> void foo(Iter b, Iter e);
Thank you.
//*****code starts here*****************************
#include <vector>
using std::vector;
template<typename T> void foo( vector<T> & a )
{
vector<T>::iterator i; // ERROR, can't use iterator
}
int main()
{
vector<int> a;
foo(a);
}
//******code ends here ****************************
//****** compiler: gcc 4.1.3 ************************
Can anyone tell me why it's not allowed to use the iterator this way?
Maybe the best way is to use Iterator directly as STL does.
template<typename Iter> void foo(Iter b, Iter e);
Thank you.