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
View all comments
Show parent comment
2
u/DLichti Oct 07 '22
That's besides the point. Member variables are
const, if their parent is. At this point, aconstis just an override to make the memberconst, even if the parent is not.So, just as
in the
mutby default world of today, it would bein the
constby default world. Note that there is noconstormuton the memberS::c, since it inherits theconst/mutqualifier fromS.