gouki said:
class X {
// members
public:
int foo() const;
}
int X::foo() const // what is the const for???
{
//do something
}
It states that the X::foo() function does not modify the "observable"
state of the object. In other words from the callers perspective it
doesn't matter whether someone has called the X::foo() in past or not.
A 'getter' function is a typical example of a const function.
When a member function is declared const, that function cannot change
member variables or call other non-const functions on itself or its
members. An excepion to this rule are 'mutable' members, which may be
modified by a const function. Mutable members are typically used for
caching purposes.