Hacker News new | ask | show | jobs
by sirseal 4114 days ago
I'm not that great at C++, but can't you use the const keyword to declare that something's value isn't changing?
2 comments

You can. If you want to write immutable C++ simply declare every single variable const. Done.

The only difference between C++ and "immutable by design" languages is that in C++ you'd have to write your own little processor to ensure that your rule is followed (this is no big deal, and I've written much more complex processors to enforce C++ coding standards as part of the build.)

const / final in most languages don't prevent the object from being mutated. They just stop the variable binding from being changed.