So far I have always been using vector::clear() before deleting the vector. But is it necessary? Isn't the vector::clear() function called in destructor anyway?
// Consider I have this vector
std::vector<uint32_t>* myVector = new std::vector<uint32_t>(50);
... // vector gets filled
myVector->clear(); // <-- redundant??
delete myVector;
myVector = nullptr;
std::vector
usingnew?
Do you have a particular reason to do so?new
to create the vector.std::unique_ptr
is perfect for this. It's C++14, which your compiler should have by now. Tryauto x = std::make_unique<std::vector<uint32_t>>(50)