
On 4/8/2011 8:43 AM, Jim Hodapp wrote:
I am using a ptr_vector<MyAbstractType> in a class called Container to store pointers to derived types inherited from MyAbstractType. In my Container class, I want to have a member function which returns the ptr_vector<MyAbstractType>. First, am I better off modelling this "getter" as an iterator over this ptr_vector or is it proper to return the ptr_vector itself? Right now, when trying to return the ptr_vector itself (a copy of it) I am getting an error: "/usr/include/boost/ptr_container/clone_allocator.hpp:34: error: cannot allocate an object of abstract type 'MyAbstractType'
The function prototype for the getter is: ptr_vector<MyAbstractType> GetDestinations() const
Is ptr_vector trying to make a copy of each MyAbstractType contained instead of copying the pointer value itself? This would indicate that I need a get() type method for ptr_vector like what a scoped_ptr has. Any recommendations on how to design this situation?
Thanks,
Jim _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Yes, returning a copy of ptr_vector makes a copy of all of its objects for the same reason that std::vector<object> does. It "owns" all of the objects. It is not the same as std::vector