On 11/21/05, Keith Weintraub
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