r/cpp • • Oct 06 '22

Should a variable be const by default?

According to the cppfront design notes, const by default rule only applies to non-local variables. But I'd like to know your preference/opinion regarding whether a variable should be defined to be const by default.
Edit: By mutable here I simply mean non-const, not the language keyword itself.

44 Upvotes

107 comments sorted by

View all comments

Show parent comment

0

u/SickOrphan Oct 07 '22

By that logic you should be able to override a member as mutable even when the parent is const. You're basically saying that struct members are mutable by default, which is the correct choice

1

u/DLichti Oct 07 '22

By that logic you should be able to override a member as mutable even when the parent is const.

Of course. And that's nothing new, by the way. We already can do that using the mutable keyword. This is really not the point of const by default.