When const is used in this context, it means the method is read-only, which basically means the method cannot alter any non-mutable data member. In other words, if a data member isn't declared mutable, operator( ) can't modify it. Read-only methods can only call read-only methods. Finally, the displayed definition is only valid within a class scope.
Edit:
I mentioned mutable. Here's an example:
1 2 3 4 5 6 7 8 9 10 11
class Example
{
private:
mutableint Member_;
public:
Example &operator ( ) ( ) const // Read-only
{
this->Member_ = 10;
}
};
The mutable keyword can only appear in a class member declaration. The keyword indicates that the member can be modified through read-only methods.
Additional Edit:
You also asked for scenarios when it would be used. When the class in which a read-only method is defined is instantiated and declared constant, the compiler will invoke (call) the read-only version of the method (if it exists). Consider this example: