What is the meaning of const
in declarations like these? The const
confuses me.
class foobar
{
public:
operator int () const
The const means that the method promises not to alter any members of the class. You'd be able to execute the object's members that are so marked, even if the object itself were marked const
:
const foobar fb;
fb.foo();
would be legal.
See How many and which are the uses of “const” in C++? for more information.