[webkit-dev] Do we have a style preference about const member functions?
ggaren at apple.com
Tue May 31 10:59:38 PDT 2011
>>> Even in a class that is used in a tree, I still think simple member variable accessor methods (that do not return tree neighbors) should be const.
>> OK. Why?
> Because it indicates to me and the compiler, that the method doesn't have side effects.
A const member function can have side effects. It can modify any global state outside the object. It can also modify sub-objects inside the object, and return non-const references to sub-objects and related objects that might be used to produce side-effects at any time.
It's exactly statements like this that make me think that const member functions are a bad idea -- people think they provide a guarantee, but they don't.
More information about the webkit-dev