4 ms·
const, of course, comes from C, where it works pretty well; unfortunately, C++ introduced features (e.g. templates) that didn't work well with const, resulting
by JoachimSchipper 16y ago
const, of course, comes from C, where it works pretty well; unfortunately, C++ introduced features (e.g. templates) that didn't work well with const, resulting in stuff like vector::const_iterator (like vector::iterator, but for const vectors. It's completely different from vector::iterator, or so the compiler insists.)
Java is meant to be "C++ without the sharp bits", and removed this feature (and a host of other stuff); I imagine the fact that arrays are not "OO" enough has also something to do with it. C# is meant to be "Java done right/the MS way", and followed suit.
- scott_s 16y agoThe concept of const actually comes from C++, and was back-ported to C. I see how const_iterator can be a stumbling block, but I'd like to hear your reason for why it doesn't work well. It is different than iterator, since const_iterator accesses const values (by convention).