Boost logo

Boost :

From: Hugo.Duncan_at_[hidden]
Date: 2002-03-19 11:42:26

I am trying to use weak_ptr to maintain information on a heterogeneous
collection of objects held in shared_ptr's.

As part of this I would like to be able to write the following:

  boost::shared_ptr<int> i;
  boost::weak_ptr<void> j;

Would it be possible to add the following overload for the constructor to enable this usage, or is this considered a mis-use of weak_ptr ?

weak_ptr(weak_ptr<void> const & r): px((element_type*)r.px), pn( // never throws


At the moment this gives a compiler error

Borland: Error E2034 c:\usr\boost\boost/weak_ptr.hpp 45: Cannot convert 'void * const' to 'int *' in function weak_ptr<int>::weak_ptr(const
weak_ptr<void> &)
MSVC6: c:\usr\boost\boost/weak_ptr.hpp(46) : error C2440: 'initializing' : cannot convert from 'void *const ' to 'int *' Conversion from 'void*' to
pointer to non-'void' requires an explicit cast
gcc: c:/usr/boost/boost/weak_ptr.hpp:45: ANSI C++ forbids implicit conversion from `void *' in assignment

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