"Right" way to deallocate an std::vector object
- by Jacob
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?