Boost logo

Boost :

From: Christian Kreibich (kreibich_at_[hidden])
Date: 2002-04-05 08:46:43


Hi all,

my question is related to your smart pointer package which I've been
using for a long time now, although the core of my problem is just one
of circular dependencies, and I'm kind of embarrassed because the answer
must be pretty obvious.

I usually use your smart pointers like this:

class A
{
public:
        typedef boost::shared_ptr<A> ptr;
// ...
};

so that afterwards I can conveniently access the smart pointers as

A::ptr aptr(new A(...));

My problem now appears when I have two classes that use each other's
smart pointers, for example as in here:

class A
{
public:
        typedef boost::shared_ptr<A> ptr;
        virtual B::ptr createB();
};

class B
{
public:
        typedef boost::shared_ptr<B> ptr;
        virtual void setA(A::ptr aptr);
private:
        A::ptr _aptr;
};

You get the idea. Is there a way to keep using my typedef style within
the classes and resolve the circular dependencies? On a more general
note, what is the suggested idiom for handling this situation?

Any help/pointers much appreciated.

Cheers,
Christian.

-- 
________________________________________________________________________
                                                    http://www.whoop.org

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk