Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2004-01-04 03:03:22


"Dan W." <danw_at_[hidden]> wrote in message
news:bt8glf$3lf$1_at_sea.gmane.org...
> > 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.

Please don't obscure the discussion by pointing out language details..

> 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,

You cannot make this statement and think it is a universal truth. To me it
is part of the state.
There is nothing to discuss. Some people like it one way, others don't. Both
views should be respected.

>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?

because the state of the object depends recursively on what member (pointers
or not)
that the object owns.

br

Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk