What is the element value in an uninitialized vector?

前端 未结 3 1130
孤独总比滥情好
孤独总比滥情好 2021-01-28 08:31

If I create a vector like vector v(10); what is the default value of each element?


Also, what if it is a vector v(

3条回答
  •  天命终不由人
    2021-01-28 08:54

    The answer to your second question is similar; vector v(10) will create an array of 10 myUnions initialized with their default constructor. However note that: 1) Unions can't have members with constructors, copy constructors or destructors, as the compiler won't know which member to construct, copy or destroy, and 2) As with classes and structs, members with built-in type such as int will be initialized as per default, which is to say not at all; their values will be undefined.

提交回复
热议问题