Boost logo

Boost Users :

From: Loïc Joly (loic.joly_at_[hidden])
Date: 2007-04-12 08:10:14


Hello,

I have the following classes:

class Owned;
class Owner
{
   unknownType getOwned(int i);
   vector<Owned> owned;
};

Owner will be handled in the client code by shared_ptr. At some places,
the client code will only know one owned object, obtained through
getOwned, therefore, the owned object should contain a shared_ptr to its
owner, to make it survive. Now, my question is: What should be unknownType?

If I make unknownType a classic shared_ptr<Owned>, I have a circular
reference. What I would like would be a way to have a kind of
shared_ptr<Owned> that would use the ref count of the owner. Is this
possible to do?

The alternative I currently envision are:

- Use intrusive ref count in Owner and make Owned shared_ptr use the
same ref count, using something similar to the technique described in
"Using a shared_ptr to hold a pointer to an object with an embedded
reference count"

- Make unknownType a class that contain a shared_ptr<Owner> and a
Owned*, and forward all its functions to Owned.

What do you think of them ?

Thank you,

-- 
Loïc

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