I was wondering if there are any advantages to declaring a function const
.
I know that it means that the method cannot modify any non-static class members, but is the only purpose for doing this is to prevent someone from re-implementing the function as something that does modify non-static members, or are there performance differences as well? If there are performance differences, is it likely that the compiler would usually do a better job than humans, such as with inline
functions?
Just to clarify, I am asking about the difference between the following member functions:
float getWidth() const
{
return width;
}
float getWidth()
{
return width;
}