Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-07-28 02:52:14


Unfortunately, the solution proposed below is unacceptable, because it would
allow construction of shared_ptr<X> from shared_ptr<Y> even where X and Y
are unrelated types. That code should only compile where X and Y are the
same type or where Y is derived from X.

-Dave

----- Original Message -----
From: "Gernot Neppert" <gn_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, July 27, 2000 10:05 AM
Subject: [boost] shared_ptr implementation without template friends

> Hi!
> I've been using the template class "shared_ptr" with a compiler that
doesn't
> support template friend declarations (You will have guessed already: It's
> Microsoft VC++ 6).
> So, the symbol BOOST_NO_MEMBER_TEMPLATE_FRIENDS is defined, and everything
> works fine - except that the members of the class become publicly exposed.
> This is really annoying, so I came up with a proposal. Although it
> introduces an ugly reinterpret_cast, this is confined to two methods
> (templated ctor and assignment operator), whereas the additional "public:"
> affected the entire class. Here's the code for the ctor:
>
> #if defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS )
> template<typename Y>
> shared_ptr(const shared_ptr<Y>& r) throw() : px(r.get()) {
> ++*(pn = reinterpret_cast<const shared_ptr<T>&>( r ).pn);
> }
> #else // original version
>
> template<typename Y>
> shared_ptr(const shared_ptr<Y>& r) throw() : px(r.px) {
> ++*(pn = r.pn);
> }
>
> #endif


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