Boost logo

Boost Users :

From: Michael B. Edwin Rickert (panda_at_[hidden])
Date: 2005-07-19 16:46:30


Edson Tadeu wrote:
> Is there an weak_ptr<> equivalent to the intrusive_ptr<>, to handle
> ownership cycles?

Nope. To make a safe weak_ptr, one must mantain the count seperately, in
which case you might as well be using shared_ptr, as that's just what
that does. If you don't care for safety (by which I mean, you know you
won't use your "weak" pointers when the object is dead) you might as
well just use a raw pointer.

A similar post which covers the same topic:
http://lists.boost.org/MailArchives/boost/msg40413.php

This post also covers creating a shared_ptr from an intrusive_ptr, which
could in turn be used to create weak_ptr objects if you really need them
- but the pointee will be considered "destroyed" by the weak_ptrs when
that series of shared_ptrs is destroyed, rather than when it actually is.

-Mike


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net