"Right" way to deallocate an std::vector object
Posted
by Jacob
on Stack Overflow
See other posts from Stack Overflow
or by Jacob
Published on 2010-06-16T15:08:25Z
Indexed on
2010/06/16
15:12 UTC
Read the original article
Hit count: 218
The first solution is:
std::vector<int> *vec = new std::vector<int>;
assert(vec != NULL);
// ...
delete vec;
An alternative is:
std::vector<int> v;
//...
vec.clear();
vec.swap(std::vector<int>(vec));
The second solution's a bit of a trick --- what's the "right" way to do it?
© Stack Overflow or respective owner