array initialisation

后端 未结 3 1257
孤独总比滥情好
孤独总比滥情好 2020-12-18 16:52

I\'m quite certain that arrays of built in types are unitialized, whereas arrays of UDTs are default initialized.

int foo[5]; // will contain junk
Foo foo

3条回答
  •  情歌与酒
    2020-12-18 17:28

    It says in the C++ standard, in 8.5.9:

    If no initializer is specified for an object, and the object is of (possibly cv-qualified) non-POD class type (or array thereof), the object shall be default-initialized; if the object is of const-qualified type, the underlying class type shall have a user-declared default constructor. Otherwise, if no initializer is specified for a non-static object, the object and its subobjects, if any, have an indeterminate initial value.

提交回复
热议问题