Vector template

This is a simple code printing the elements in a vector template.

But if I define (in line 8)

vector <T>::iterator i;

rather than

vector <double>::iterator i;

then a compiler error occurs.
Why is that?

Thank you.

#include <iostream>
#include <vector>
using namespace std;

template <class T>
void print( vector <T> &myVector )
{
vector <double>::iterator i; // I like to change it to vector <T>::iterator
for( i = myVector.begin(); i < myVector.end(); i++ )
{
cout << *i << endl;
}
}

int main()
{
int n = 10;
vector <double> myVector;

for( int i = 0; i < n; i++ )
myVector.push_back( i );

print( myVector );
}

[code] "Your code goes here" [/code]
Try class vector<T>::iterator i; //or typename
Thanks!
Topic archived. No new replies allowed.