Boost logo

Boost Users :

Subject: Re: [Boost-users] casting shared pointers to derived classes
From: spam-receiver_at_[hidden]
Date: 2012-01-11 11:17:50

Cast a Layer to an OutputLayer:

boost::shared_ptr<Layer> layer = getLayer();
boost::shared_ptr<OutputLayer> outputLayer =

But please consider to declare your calculation method virtual and to
provide different implementations in your derived classes. You would not
have to cast at all then.


-------- Original Message --------
Subject: [Boost-users] casting shared pointers to derived classes
From: Don Wilde <donintel11_at_[hidden]>
To: boost-users_at_[hidden] <boost-users_at_[hidden]>
Date: Wed Jan 11 2012 16:18:55 GMT+0100

> Greetings, all -
> I am updating a neural network package from the DOS days to modern C++
> standards.
> I have a shared_ptr to a vector of shared_ptrs of type Layer. This class
> has derived classes OutputLayer, MiddleLayer and InputLayer. Each of
> these has their own method for calculating output updates, so I need to
> be able to cast. from boost::shared_ptr<Layer> to
> static_cast<*>().
> Unfortunately, VC++ 2010 will not allow me to do so. It won't even allow
> a reinterpret_cast. I've looked on the Web and I also have Schalling's
> guide to Boost.
> Thank you in advance for your guidance. I'm using boost_1_47_0, if that
> makes a difference. :D
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at