|
Boost : |
Subject: Re: [boost] dynamic_cast with WeakPtr?
From: Sören Freudiger (muffmolch_at_[hidden])
Date: 2008-11-24 15:09:54
ups, sorry, my fault.. the example seems to work, but I run into that
problem because I tried to perform an dynamic_cast on that weak_ptr. How
this should be done in this simple example?
class Base
{
public:
boost::weak_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;
//like that?
boost::shared_ptr<Derived> pD2 = boost::shared_dynamic_cast< Derived
>( a->neigh.lock());
}
}
-----Ursprüngliche Nachricht-----
Von: Sören Freudiger [mailto:muffmolch_at_[hidden]]
Gesendet: Montag, 24. November 2008 21:03
An: boost_at_[hidden]
Betreff: dynamic_cast with WeakPtr?
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