I'm trying to learn the STL library and I'm having a weird problem. This code compiles perfectly:
void Show(vector<int> myvec)
{
vector<int>::iterator it;
cout << "Vector contains:";
for( it = myvec.begin(); it < myvec.end(); it++)
{
cout << " " << *it;
}
cout << endl;
}
while this one gives me an error message at compile time:
template <class T>
void Show2(vector<T> myvec)
{
vector<T>::iterator it;
cout << "Vector contains:";
for( it = myvec.begin(); it < myvec.end(); it++)
{
cout << " " << *it;
}
cout << endl;
}
The error is:
$ g++ hello.cpp
hello.cpp: In function ‘void Show2(std::vector<T, std::allocator<_Tp1> >)’:
hello.cpp:19: error: expected ‘;’ before ‘it’
hello.cpp:21: error: ‘it’ was not declared in this scope
It seems a very simple mistake, but I couldn't find it.