Top-level const to indicate that the pointer itself is a const. When a
pointer can point to a const object, we refer to that const as a low level
const.
For reference, you always can’t change it, so only low-level const.
function return value. ( just used for const reference)
member function.
The const qualifier prevents code inside the function from modifying the
parameter itself. Such an assurance helps you to quickly read and
understand a function. Under some circumstances, this might even help the
compiler generate better code.
In C++, When you use pointer or reference as functionparameter, You should always put const in front of it. Becuause90% you don’t need to modify it. Once you compiler bark, then you
can delete const, It’s funny.
When function return build-in value, don’t use const at all.
If you want to return a member of a object from a const method, you
should return it using reference-to-const (const X& inspect() const) or
by value ( X inspect() const). const member method return valueor const reference.
The most common use of const overloading is with the subscript
operator. You should generally try to use one of the standard
container templates, such as std::vector, but if you need to
create your own class that has a subscript operator, here’s
the rule of thumb: subscript operators often come in pairs.
"mutable" allows you to modify a member variable in a class by a const
method.
Behind "mutable", It’s bitwise const and logical const. Logical const is when
an object doesn’t change in a way that is visible through the public
interface. An example would be a class that computes a value the first time
if required, then caches the result.