views:

55

answers:

1

How to exclude pointer from boost::ptr_vector without his deletion? =)

+4  A: 
ptr_vector<A> v;
v.push_back(new A);
A *temp=v.release(v.begin()).release();

At this point you own the object exclusively through temp. If you don't need it, use this instead:

v.release(v.begin());

[code credit: see here]

Steve Townsend