Correct way to initialize std::vector data member

See http://en.cppreference.com/w/cpp/language/default_initialization

Default initialization is performed in three situations:

  1. when a variable with automatic storage duration is declared with no initializer
  2. when an object with dynamic storage duration is created by a new-expression without an initializer
  3. when a base class or a non-static data member is not mentioned in a constructor initializer list and that constructor is called.

The effects of default initialization are:

  • If T is a class type, the default constructor is called to provide the initial value for the new object.
  • If T is an array type, every element of the array is default-initialized.
  • Otherwise, nothing is done.

Since std::vector is a class type its default constructor is called. So the manual initialization isn’t needed.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)