Boost logo

Boost Users :

From: Faheem Mitha (faheem_at_[hidden])
Date: 2005-10-30 14:30:09


Hi,

I was wondering what the recommended way was to downcast shared
pointers.

I have a a base class, Base, and a derived class Derived. I have a
Base shared pointer which points to a Derived object.

shared_ptr<Base> d;

As part of a unit test, I'm trying to extract the Derived object from
it.

*static_cast<Derived *>(d.get());

Here I'm extracting the raw pointer, downcasting it to Derived, and
then taking the value.

It would be nice if there was some method to downcast the shared_ptr
itself.

Thanks in advance. Please CC me on any reply.

                                                            Faheem.


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