|
Boost : |
From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-10-03 15:11:56
No, that wont work. That would still require it's base to be copied--the
same copy that occurs already.
If you used composition, the const version could maintain a reference to the
non-const version that was passed in, but that isn't safe because it doesn't
imply that it has the same scope as the reference it would maintain.
Therefore, it seems no implicit conversion without copying is possible.
"Schoenborn, Oliver" <Oliver.Schoenborn_at_[hidden]> wrote in message
news:35C5DD9F60FED21192B00004ACA6E6C70151C87D_at_nrclonex1.imti.nrc.ca...
> > >
> > I haven't looked real close, but doesn't the subsection titled
> > "Smart Pointers and const" in Item 28 of Scott Meyers
> > _More Effective C++_ contain a solution to this problem?
> > Basically, it describes SmartPtr<T> derived from
> > SmartPtrToConst<T> and SmartPtrToConst<T> containing
> > a union of const and non-const pointers to T. Unfortunately,
> > this would require changing shared_ptr.
>
> Another option is to have shared_ptr<T> inherit non-publicly from
> shared_ptr<const T>, with a method to get a reference to the base. This
> requires a little bit more maintenance of code since pretty much all of
the
> methods of the derived have to be forwarded to the base, but it's not
> excruciating either. It avoids the copy construction too.
>
> Oliver
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk