Default initialization of std::array?

前端 未结 5 999
青春惊慌失措
青春惊慌失措 2020-11-28 04:40

With C++11 std::array, do I have the guarantee that the syntax std::array x; will default-initialize all the elements of the array ?

5条回答
  •  青春惊慌失措
    2020-11-28 05:11

    Both T x[N]; and std::array x; default-initialize every element of the array.

    For example, if T = std::string, every element will be an empty string. If T is a class without a default constructor, both will fail to compile. If T = int, every element will have indeterminate value (unless that declaration happens to be at namespace scope)

提交回复
热议问题