Maxpm Maxpm - 5 months ago 38
C++ Question

Constant Member Functions

After reading this, it is my understanding that declaring a method as

prevents it from accidentally modifying the class's member variables.

  • Are
    methods commonly used?

  • Should they be used for everything that shouldn't modify member variables?


Yes, const should always be used, when appropriate.

It lets your compiler check your application logic, statically asserting const-correctness for free!

Some people even say that const should be the default, and you should be forced to use mutable for what is non-constant.