|
Boost : |
From: Gernot Neppert (gn_at_[hidden])
Date: 2000-07-27 09:05:57
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