Boost logo

Boost :

From: Schoenborn, Oliver (Oliver.Schoenborn_at_[hidden])
Date: 2002-10-03 14:58:08


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


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