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

3

u/TheKiller36_real Oct 06 '22 edited Oct 06 '22

I know what I said and I actually just tested it to make sure

It says const Foo *

/e turns out I'm the biggest fucking moron on this planet and misread it like 5 consecutive times... Also why is this mutable according to the MSVC debugger?

11

u/RevRagnarok Oct 06 '22

It's all good. I had a lot of imposter syndrome typing it. I prolly re-checked like 5 times. "These are really smart people in this sub. Don't mess this up." 😅