[Cs3] end() vs cend()
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Sep 28 16:57:38 EDT 2021
CS3 students,
So end() returns a regular iterator while cend() returns a
const-iterator. Neither can be dereferenced. Howefver, decrements are
allowed for both iterators. After which a regular iterator can be used
to modify the element while a const-iterator may not be.
vector <int> v = {1, 2, 3};
*(v.end() -1) = 4; // will work
*(v.cend() -1) = 4; //will not work
Thanks,
--
Mikhail
More information about the cs3
mailing list