$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Dan W. (danw_at_[hidden])
Date: 2004-01-04 02:51:12
> The most important application of propagating constness is when storing an
> object by
> pointer in a class:
>
> class X
> {
> smart_ptr<My_polymorhic_type> p_;
> public:
> int bar() const
> {
> return p_->this_is_also_a_const_function(); // compile time error if
> not
> }
> };
That's neither a const, nor a non-const function of p_, you're calling;
it's a function of what p points to. That a function is const means
that it doesn't change the class state, i.e.: what _address_ the pointer
points to. But the target at that address is _not_ part of the state of
this class, so why should the constness of a member function of _this_
class have to bear responsibility for some class elsewhere, just because
we have its pointer?
If I said to you, I'll pay you a thousand dollars to keep this phone
book for one night, and make sure it's not altered in any way, and you
agree... Now, next day I come to pick up the phone book and you ask for
the 1G, and I say, "well, you didn't do your job", and you say "how not?
the book is safe!" and then I say "125 people died last night, that were
listed in that phone book, you were to prevent that".