Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2000-03-13 17:32:07


>> When I have a pointer in a class, I often want the const methods of
>> the class to pass the constness through to the pointed-to members.
>> I realize that this is NOT the behavior of a naked pointer.
>
> I see. This seems like good behavior for pointers that express ownership
> like scoped_ptr, shared_ptr and CopyPtr/ClonePtr/deep_ptr.

After thinking about this further, I think this is useful for deep_ptr, but
not for scoped_ptr or shared_ptr.

In the case of scoped_ptr, it's not useful to have it as a member of an
object in the first place, so how it behaves as a member of a const object
seems irrelevant.

In the case of a shared_ptr, there's just too wide a hole in the const,
since you can always copy the const shared_ptr into a non-const shared_ptr
(intentionally or by accident), and thus gain read/write access to the
pointed-to object.

But in the case of a deep_ptr, there's no hole. For deep_ptr, I think the
"qualified" semantic of having a const deep_ptr always dereference to a
const reference/pointer makes great sense.

    -- Darin


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