3 ms·
Could you explain why would I need to write two versions of methods? I always liked C++ const-ness, the only drawback that I see is that const-ness should be de
by vbezhenar 9y ago
Could you explain why would I need to write two versions of methods? I always liked C++ const-ness, the only drawback that I see is that const-ness should be default and something like `sideeffect` modifier should be applied for non-const functions.
- Ded7xSEoPKYNsDd 9y agoIn 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.