dimanche 29 novembre 2015

Why does the STL provide a const overload for std::container::begin and std::container::end functions?

Take any STL container in mind which uses iterators.

The following is valid:

iterator begin();
const_iterator begin() const;
const_iterator cbegin() const;

Now I don't understand why the second line exists. Could someone provide a nice example where iterator begin(); wouldn't work and it can't be replaced by const_iterator cbegin();... begging the need for const_iterator begin();?

Aucun commentaire:

Enregistrer un commentaire