Hi all Suppose I have two classes A and B like those ones : class A { // ... B *m_b; }; class B { // ... std::vector m_a; }; m_b is used to know who is the parent of the object. I would like to use smart pointers. How can I do this ? Thanks in advance -- Le temps des cerises reviendra. Dans l'immédiat, c'est le temps des noyaux. Courage.
I believe you can do what you want like this:
#include
________________________________________ From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Olivier Tournaire Sent: Thursday, May 10, 2007 2:08 PM To: boost-users@lists.boost.org Subject: [Boost-users] Smart pointers Suppose I have two classes A and B like those ones : class A { // ... B *m_b; }; class B { // ... std::vector m_a; }; m_b is used to know who is the parent of the object. I would like to use smart pointers. How can I do this ? [Nat] Without thinking about it too hard... My first implementation would use std::vector< boost::shared_ptr<A> > for m_a (parent object responsible for lifespan of its children) and boost::weak_ptr<B> for m_b (child object not responsible for lifespan of its parent).
#include
participants (4)
-
Andrew Holden
-
Nat Goodspeed
-
Olivier Tournaire
-
TOL Tsagarakis Manos