std::vector::clear() in constructor and destructor
16:47 19 Oct 2009

I encounter many times with code where std::vector::clear() of class member of type std::vector is called in constructor and destructor.

I don't see why it's required:

  1. constructor - the class member of type std::vector is empty by default, so no need to call clear().
  2. destructor - the class member of type std::vector will be destroyed as part of standard destruction of object containing it. As part of vector destruction all value objects contained in it will be destroyed (if it heap allocated pointers to memory, they should be deleted "manually"), so again no need to call clear().

Do I miss something?

c++ stl