It doesn't do anything. It is a carry-over from C which indicates (in C++) that the function takes no arguments. The following signature is equivalent
int method() const;
The const
following the name of the function means that (since this implies the function is a class method) the function is not allowed to change any of the member variables of the class instance.
To implement a "setter" and "getter" you typically have something like this
class Foo()
{
public:
int GetX() const { return x; } // getter method
void SetX(int x_) { x = x_; } // setter method
private:
int x;
}
Notice that we can declare the getter const
because it does not modify the value of x
, but the setter cannot be const
because the whole purpose of the method is to assign a new value to x
.