Mike Wahler wrote:
What does const mean when it appears at the _end_ of a function signature,
like this:
int f() const
{
return 50;
}
This syntax is only valid for a member function.
It means that the function will not modify the
object for which it was invoked.
And in turn it means that it is OK to call it on a const object
(and that the this pointer refers to a const object).
This is important for not only does it mean that you are prohibited
from attempting to change the object inside the const method, that
this will be selected when another non-const overload is present
struct S {
void f() const;
void f();
void g();
void h() const;
};
S o;
o.f(); // calls nonconst f()
o.g(); // ok
o.h(); // ok
const S co;
co.f(); // calls const f()
co.g(); // ill-formed! can't call non-const method on const object.
co.h(); // ok