On 2007-09-25 17:32:26 -0400, Erik Wikstr??m <Erik-wikstrom@telia.com> said:
On 2007-09-25 22:37, Kira Yamato wrote:
So to me, declaring an object 'const' is really just a mechanism to
allow a certain subset of the object's member functions to be called
(those that are declared 'const') and disallow calling the other member
functions, (those that are not declared 'const'). No other conditions
can be assumed.
I would hardly call this a pitfall, and I have yet to meat anyone with a
bit of OO programming skill who fail to grasp the concept of constant
objects (namely that their state are constant/unchangeable).
What is the state of an object? A state of an object is supposed to be
a set of data that determines the behavior of an object. In another
word, knowing the state of an object would dictate what its functions
do given some inputs. Otherwise, what is the point of knowing an
object's state?
So, if you say that declaring an object 'const' should keep its state
constant, then its member functions should yield the same output for
the same input since the object remains in the same state!
However, this is not the case as shown in the example.
state. In the example above this is not the case, and there is thus no
need to for the results to be the same. Consider the following: