Boost logo

Boost Users :

Subject: [Boost-users] Returning a ptr_vector of an abstract data type
From: Jim Hodapp (james.hodapp_at_[hidden])
Date: 2011-04-08 09:43:59

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?



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