Const usage


I’m curious about this idiom I have seen frequently in JUCE:

What are you trying to communicate by using const in this way? After much digging around, I found this in the Google C++ style guide:

Is that the idea? Certainly makes sense in this context.


No, what they’re talking about would be “const Thing*”, and not “Thing* const”.

If you see “Thing* const”, it just means that the pointer is a constant, not the object itself. So from a caller’s perspective, this is irrelevent, but in the implementation of the method, I like to keep everything const where possible. (In practice, this probably has very little usefulness…)


OK, thanks for the explanation.

Not so sure about the Google thing… since in this context, they are referring to “const pointer” as an alternative to a reference, I am inclined to think that they mean “Thing* const”:

They don’t offer an example, so I can’t say for sure though.


This is a good read if you want to learn more about the topic:±faq-lite/const-correctness.html#faq-18.5