A "const function," marked by the term const following a function declaration, causes a compiler error if this class function changes a class member variable.
However, accessing class variables within the function is permitted, but writing within the function will result in a compiler error.
This pointer is implicitly sent to the function.
So, a method like int Foo::Bar(int random arg) (without the const at the end) yields a function like int Foo Bar(Foo* this, int random arg) and a call like Foo f; f.
Internally, Bar(4) will be equivalent to Foo f; Foo Bar (&f, 4).
Adding the const at the end (int Foo::Bar(int random arg) const) makes the declaration with a const this pointer: int Foo Bar(const Foo* this, int random arg).
Because the type of this in this example is const, no changes to member variables are available.
It is feasible to relax the "const function" limitation that prevents the function from writing to any class variable.
These class variables are tagged with the term mutable to allow them to be editable even when the function is declared as a "const function."
Thus, if a class variable is designated as changeable and a "const function" writes to it, the code will compile correctly and the variable can be changed.
(C++11)
Changing the placement of the const keyword in a C++ statement has completely distinct semantics, as is typical when working with the const keyword.
The preceding const use only applies when const is added to the end of the function declaration after the parenthesis.