Boost logo

Boost :

Subject: [boost] dynamic_cast with WeakPtr?
From: Sören Freudiger (muffmolch_at_[hidden])
Date: 2008-11-24 15:02:45


Hi @all
Maybe you can help me. I tried to use weak_ptr for breaking circular
references, but I found out that this pointers can't handle derived classes.
But in my classes I have some neighbor relations that I want to tore with
shared_ptr:

class Base
{
public:
  boost::shared_ptr<Base> neigh;
};

class Derived : public Base
{
};

int main()
{
   {
     boost::shared_ptr<Base> a(new Base);
     boost::shared_ptr<Derived> d(new Derived)

     a.neigh = d;
     d.neigh = a;
   }
   //both objects are in memory because of circular references, but weak
pointer doesn't work,
   //becaus eit seems to be unable handling derived classes... and there's
no dynamic cast
}

How do you solve problems like that with boost pointers avoiding circular
references?

Best reagrds,
  SirAnn

  


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