Vie
Vie

Reputation: 853

How to remove pointer from boost::ptr_vector without object being deleted?

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

Upvotes: 1

Views: 870

Answers (1)

Steve Townsend
Steve Townsend

Reputation: 54138

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]

Upvotes: 4

Related Questions