On Fri, Mar 18, 2011 at 8:55 AM, Ted Byers <r.ted.byers@gmail.com> wrote:
The type for the container would be: std::vector<boost::shared_ptr<base_type> >
boost::shared_ptr<base_type> and boost::shared_ptr<derived_type> are two different types. You can't cast from the one to the other without writing code to do it. So, to make one vector containing (smart) pointers to instances of any or all the derived types, you would have to cast the pointers to instances the derived types to the base before you create the shared_ptr.
Put the return value from new directly into a shared_ptr -- it'll just work! When the object expires, shared_ptr will not call the destructor through a base pointer, so the base destructor should be protected (and non-virtual) to protect from someone attempting to call delete on a base pointer. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode