One of the two overloads allows you to get a link constto a vector element accessed through a variable const. Another allows you to get a link not constto an element of a vector that is accessed through a variable const.
If you did not have a version const, you will not be allowed to compile the following instances:
void f(vector<int> const& v)
{
cout << v[0];
}
In the following example, a non-constant version is called instead, which returns a reference not constto the first element in the array and allows, for example, to assign a new value to it:
void f(vector<int>& v)
{
v[0] = 1;
}
source
share