Maxpm Maxpm - 1 year ago 123
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download