Const usage


#1

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.


#2

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…)


#3

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”:

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Reference_Arguments

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


#4

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