R
Russ Ford
How does one define an iterator for a constant vector?
ie:
void printvector (vector<int>& arr)
{
vector<int>::iterator i;
for (i=arr.begin(); i<arr.end(); ++i)
cout << *i << endl;
}
works fine, but if I change the prototype to
void printvector (const vector<int>& arr)
I get a compile error on the for line about trying to convert a const int*
const to an int*.
How do I specify that it's the vector that's constant and not the iterator
itself?
Much appreciated.
Russ
ie:
void printvector (vector<int>& arr)
{
vector<int>::iterator i;
for (i=arr.begin(); i<arr.end(); ++i)
cout << *i << endl;
}
works fine, but if I change the prototype to
void printvector (const vector<int>& arr)
I get a compile error on the for line about trying to convert a const int*
const to an int*.
How do I specify that it's the vector that's constant and not the iterator
itself?
Much appreciated.
Russ