I believe you can do what you want like this:

 

#include <boost\shared_ptr.hpp>

#include <boost\weak_ptr.hpp>

 

class A;

class B;

 

typedef boost::shared_ptr<A>    spA;

typedef boost::shared_ptr<B>    spB;

typedef boost::weak_ptr<A>      wpB;

 

class A

{

   // ...

   spB m_b;

};

 

 

class B

{

    wsB                 m_wpParent;

    // ...

    std::vector<spA>    m_a;

};

 

 

I hope this helps,

Manos

 

 

 

 

 

From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Olivier Tournaire
Sent: Thursday, May 10, 2007 9:08 PM
To: boost-users@lists.boost.org
Subject: [Boost-users] Smart pointers

 

Hi all

Suppose I have two classes A and B like those ones :

Typedef


class A
{
   // ...
   B *m_b;
};

class B
{
   // ...
   std::vector<A *> 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.