Re: [Boost-users] Collections of shared_ptr<Base> and shared_ptr<Derived>

Michael, Thanks for the reply. You are absolutely right. I'm coming back to C++ after years of Java and I haven't been careful enough about reading the stl docs. One quibble with your solution is that I am doing an upcast not a down cast, but your solution worked perfectly for me. Thanks all, KW ________________________________________________ Date: Mon, 21 Nov 2005 15:29:29 -0800 From: Michael Rickert <pandamojo@gmail.com> Subject: Re: [Boost-users] Collections of shared_ptr<Base> and shared_ptr<Derived> To: boost-users@lists.boost.org Message-ID: <561a17f20511211529l1a528314od7905edcc2aa2ab7@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On 11/21/05, Keith Weintraub <Keith@archeuscap.com> wrote:
Folks,
I have come up with the following solution in template form. I would
be ecstatic to receive any feedback on either my solution or original question. I am not an expert in these things and I can use all the help any generous soul could provide.
Here is my solution:
*snip* It would seem you're overengineering things. It'd be simpler just to use std::vector's iterator constructors: std::vector< boost::shared_ptr< derived > > data; ... std::vector< boost::shared_ptr< base > > downcast_data( data.begin() , data.end() ); If you wanted to go with your original version, I'd suggest returning a managed pointer of some sort (std::auto_ptr or boost::shared_ptr) to decrease the likelyhood of a leak - or having the user pass a nonconstant reference to a vector to fill. Sorry if this has allready been covered by the time this is recieved, my posts seem to still be awaiting moderator approval. -Mike

On 11/23/05, Keith Weintraub <Keith@archeuscap.com> wrote:
One quibble with your solution is that I am doing an upcast not a down Quite correct, brain fart on my part. Hardly quibbling to clarify :-).
participants (2)
-
Keith Weintraub
-
Michael Rickert