Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2001-03-02 22:28:41

From: "Trevor Perrin" <tperrin_at_[hidden]>
> shared_ptr<int> C = new int;
> shared_ptr<const int> D =C;

With a conforming C++, this will work. However, VC6 has problems with
member templates, and so the functions that allow this to work are excluded
by the preprocessor. However, it is possible that Boost.SmartPointer can
make better use of what does work with VC6.

For example, the following changes to will make your example to compile (and
presumably work):

Change the conditional compilation expression in class shared_ptr to:
  #if !defined(BOOST_NO_MEMBER_TEMPLATES) ||
and move
  shared_ptr(const shared_ptr& r)
  shared_ptr& operator=(const shared_ptr& r)
into the #else portion of the conditional block.

Changing the expression allows VC6 to see the member templates, and moving
the non-templatized constructor and assignment operator works around a VC6
bug in which it sees the templatized and non-templatized functions as
conflicting duplicates. Moving the non-templatized versions to the #else
causes them to only be seen by compilers for which no member templates
whatever are supported. AFAICT, the non-templatized functions should have
never been there in the first place when member templates are compiled since
they add nothing that the templatized functions don't already provide.

Beman, others, does this analysis make sense? Am I missing/forgetting
anything? Should we make this change to shared_ptr, and then also imbue
shared_array with this functionality (Trevor's example is just as applicable
to arrays)? Finally, does anyone know if there are any issues with VC6
silently generating bad code that relate to this situation?

Boost list run by bdawes at, gregod at, cpdaniel at, john at