All that const
does in this case is to prevent modification of parameter variable (and in the case of classes, prevent the calling of functions that are not labelled as const
). MyClass
may be trivially cast to const MyClass
because there should be nothing that you can do to a const MyClass
that you can't do to a non-const
one. The reverse is not true, of course.
(I say "should" above, because it is of course possible to completely subvert const
semantics under C++ if you wanted to, so the presence of const
in a function prototype is really only a hopeful hint rather than a cast-iron compiler-enforced guarantee. But no sensible programmer should be breaking things like that!)