4 ms·
In C++, there need to be e.g. two overloaded versions of the index operator on a vector: one taking a const vector reference returning a const reference to the
by Ded7xSEoPKYNsDd 9y ago
In C++, there need to be e.g. two overloaded versions of the index operator on a vector: one taking a const vector reference returning a const reference to the value, and one taking a non-const vector reference returning a non-const reference to the value.
With only the first one you couldn't modify values of a vector using nice [] syntax. With only the second one you couldn't use the same nice [] syntax on const vectors. So you need both. The implementation can be identical, but the method signature is different. You end up with such duplicate functions all the time for accessor methods.