Questions tagged [ptr-vector]
43 questions
7
votes
6 answers
How to erase elements from boost::ptr_vector
So I'm trying to get rid of my std::vector's by using boost::ptr_vector. Now I'm trying to remove an element from one, and have the removed element deleted as well. The most obvious thing to me was to do:
class A
{ int m; };
boost::ptr_vector…

Roel
- 19,338
- 6
- 61
- 90
4
votes
2 answers
Moving objects from one Boost ptr_container to another
I want to move certain element from a to b:
boost::ptr_vector a, b;
// ...
b.push_back(a.release(a.begin() + i)));
The above code does not compile because the release function returns boost::ptr_container_detail::static_move_ptr<...>, which is…

Tronic
- 10,250
- 2
- 41
- 53
4
votes
1 answer
Releasing a boost::ptr_vector, not matching documentation
I'm using boost 1.37, and I'm trying to use a boost::ptr_vector, and transfer ownership of it so I can return it from a function. Looking at the boost documentation…

kevbo
- 63
- 2
3
votes
2 answers
C++: why boost::ptr_vector resize needs object to have default constructor
I am using a boost::ptr_vector over just std::vector as it will handle the deletion of all of the pointers for me. However when I do:
ptr_vector functors;
functors.resize(number_of_functors);
It complains that…

Aly
- 15,865
- 47
- 119
- 191
3
votes
1 answer
C++:member reference or pointer?
I have a collection (currently boost::ptr_vector) of objects (lets call this vec) that needs to be passed to a few functors. I want all of the functors to have a reference/pointer to the same vec which is essentially a cache so that each functor has…

Aly
- 15,865
- 47
- 119
- 191
2
votes
1 answer
Can't make a vector of a class containing a ptr_vector
I need to have a std::vector of boost::ptr_vectors. To make their management easier, I enclosed the boost::ptr_vector in a class (Zoo) and made a std::vector of it (allZoos). Look at a minimal code for reproducing this:
#include…

Hossein
- 4,097
- 2
- 24
- 46
2
votes
2 answers
Get a pointer instead of a reference from a boost::ptr_vector
I recently found the boost ptr_vector useful to manage my collection of heap-allocated objects. The pointer collection library is very nice, but unfortunately, I'm being held up by one thing.
Another part of my code needs to explicitly hold a…

cemulate
- 2,305
- 1
- 34
- 48
2
votes
1 answer
boost::shared_ptr semantics (copying)
I just wanted to have a fresh pair of eyes that the below code is correct in that:
The pointers contained in the object trifoo (stored in a ptr_vector) are the shared pointers f, g, h.
Also, what is the result of the shared_ptr copy in the…

hiddensunset4
- 5,825
- 3
- 39
- 61
2
votes
2 answers
Does ptr_vector iterator not require increments?
#include
#include
using namespace std;
class Derived
{
public:
int i;
Derived() {cout<<"Constructed Derived"<

Nav
- 19,885
- 27
- 92
- 135
2
votes
2 answers
How to retrieve a reference from a boost ptr_vector?
I have two classes: an Object class, and an ObjectManager class. The ObjectManager class stores "Objects" via a ptr_vector container. There are some instances where I need to retrieve references to these stored pointers to perform individual actions…

jbaez
- 391
- 3
- 9
2
votes
1 answer
Adding boost::ptr_vector to deque, typeid mismatch
I'm trying to add a boost::ptr_vector to a std::deque, using push_back(). When I do, I get a BOOST::ASSERT for the typeid mismatch.
In "boost_ptr_container_clone_allocator"
T* res = new T( r );
BOOST_ASSERT( typeid(r) == typeid(*res) &&
…

kevbo
- 63
- 2
2
votes
2 answers
BOOST and C++: can't seem to get polymorphism to work
I'm using ptr_vector to store "shapes". I'm trying to fill it with derived shape classes, such as "circles", and every time I try to downcast them I get bad cast.
class Shape
{
public:
virtual ~Shape() {};
virtual void print() { std::cout <<…

dubesinhower
- 43
- 1
- 3
1
vote
1 answer
C++ Sharing elements in a boost::ptr_container?
Please consider the following piece of code:
int main()
{
typedef boost::ptr_vector ptr_vector;
ptr_vector vec0;
vec0.push_back(new int(1));
vec0.push_back(new int(2));
vec0.push_back(new int(3));
vec0.push_back(new…

0xbadf00d
- 17,405
- 15
- 67
- 107
1
vote
1 answer
should I erase by myself the pointer of an boost::ptr_vector?
I was wondering if this code leak :
int main()
{
boost::ptr_vector v;
v.push_back(new char[10]);
v.clear()
}
Will the ptr_vector destructor or clear() function delete the pointers it contains or do i have to do it myself?

Ephemere
- 121
- 1
- 6
1
vote
1 answer
Derived class stored in ptr_vector not being destructed
Was trying to find the best way to use ptr_vector to store, access and release objects, especially when the stored object is inherited from other (ptr_vector should not have any issues with object slicing).
But when running the below program,…

Nav
- 19,885
- 27
- 92
- 135