What does const T& value() const mean?
This question already has an answer here:
const T& value() const {...}
This means the function value()
will return a const T&
type and in between (in the function) won't modify the class itself. Say I write:
class Cfoo
{
void foo() const
{
//Cfoo will not be modified here
}
}
If I directly quote from msdn:
Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object for which it is called. A constant member function cannot modify any non-static data members or call any member functions that aren't constant.
The const
after the method name signifies that the method does not modify any field of the object. Therefore, it can be invoked on a const
instance of the object.