C++ - value of uninitialized vector

后端 未结 5 1516
情歌与酒
情歌与酒 2020-12-03 09:28

I understand from the answer to this question that values of global/static uninitialized int will be 0. The answer to this one says that for vectors, the default construc

5条回答
  •  失恋的感觉
    2020-12-03 09:59

    The default initialization for an int type is to initialize it to 0.

    This is true of most (if not all) primitive types: char will initialize to (char)0 (or '\0' if you prefer), float will initialize to 0.0f, and any pointer initializes to NULL. For other types, the parameterless constructor is invoked.

    In general, the default initialization should happen pretty much whenever you aren't able to specify a constructor (or choose not to).

提交回复
热议问题