const reference to stl vector

i have a function that takes a reference vector
bool checkSum(const vector<int>&,int,int&);

If the vector is passed as constant refrence, an error message that says


no match for âoperator=â in âiter = ((const std::vector<int, std::allocator<int> >*)vect)->std::vector<_Tp, _Alloc>::begin [with _Tp = int, _Alloc = std::allocator<int>]()....


how to make sure you pass a constant argument of vector in a function?
I believe you can't pass a reference of a vector...
As it is a constant vector - he will need to get a constant_iterator.

1
2
3
const vector<int>& vec;
 vector<int>::iterator it = vec.begin(); //Error
vector<int>::const_iterator it = vec.begin(); // correct 
the constant iterator works but why do we not need to put it as this?

vector<int>::const_iterator it = vec.begin() const;
vector::begin() is overloaded (one const) and which one is called can be determined by the context.
Topic archived. No new replies allowed.