c++winapivisual-c++class-designfunction-qualifier

What does the `const` keyword do when it is after a function?


Possible Duplicate:
What is the meaning of a const at end of a member function?

I have seen some classes that have something like this.

void something() const;

What does const means?


Solution

  • In addition to what SRM said (that the function cannot alter any members of the class (which is not exactly true, e.g. in the case of mutable members, which still can be altered)), it means that you can call this member function on things that are const. So if you get a Foo const& foo as a parameter, you can only call members that are declared const like in your question.