Bar
is guaranteed not to change the object it is being invoked on. See the section about const correctness in the C++ FAQ, for example.
Consider two class-typed variables:
class Boo { ... };
Boo b0; // mutable object
const Boo b1; // non-mutable object
Now you are able to call any member function of Boo
on b0
, but only const
-qualified member functions on b1
.
Function can't change its parameters via the pointer/reference you gave it.
I go to this page every time I need to think about it:
http://www.parashift.com/c++-faq-lite/const-correctness.html
I believe there's also a good chapter in Meyers' "More Effective C++".
I always find it conceptually easier to think of that you are making the this pointer const (which is pretty much what it does).
Source: Stackoverflow.com