Should I always call vector clear() at the end of the function?
问题 I have some simple function that uses vector like this (pseudo code): void someFunc(void) { std::vector<std::string> contentVector; // here are some operations on the vector // should I call the clear() here or this could be ommited ? contentVector.clear(); } Should I call the clear() or this could be ommited ? 回答1: If we look at the cppreference.com entry for std::vector::~vector it says: Destructs the container. The destructors of the elements are called and the used storage is deallocated.