Boost logo

Boost :

From: Axter (boost_at_[hidden])
Date: 2005-08-16 20:01:09


----- Original Message -----
From: "Jonathan Wakely" <cow_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
Sent: Tuesday, August 16, 2005 10:39 AM
Subject: Re: Propose adding Clone Smart Pointer (clone_ptr) to theboost
library

> David Abrahams wrote:
>
>> Martin Bonner <martin.bonner_at_[hidden]> writes:
>>
>> > That looked a very clever trick. I couldn't see how clone_ptr was
>> > going to
>> > copy the dynamic type of the argument to the constructor without any
>> > information about that dynamic type.
>> >
>> > Having looked at the code, I don't think it does.
>>
>> Right, I went through the same thing. The documentation claims a bit
>> too much for this library. I expected to find some magic in the
>> library but instead I found what I already knew to be the practical
>> limitation of C++: the copying logic is captured based on the static
>> type of the pointer with which the original smart pointer was
>> initialized, not on the dynamic type of the object referred to.
>
> Which is why ptr_container requires a clone() member to ensure the
> dynamic type is available when copying. Clone_ptr has no way to access
> the dynamic type.

It does not need a clone member if you apply strict pointer ownership logic,
which is what a clone pointer normally does.

If you create the object by passing it directly to the constructor, it will
be able to clone itself with no problems.


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