Meaning of default initialization changed in C++11?

前端 未结 3 1306
栀梦
栀梦 2020-12-05 13:14

C++2003 8.5/5 says:

To default-initialize an object of type T means:

— if T is a non-POD class type (clause 9), the default const

3条回答
  •  借酒劲吻你
    2020-12-05 13:38

    According to cppreference.com (because it uses friendlier language than the standard):

    Default initialization is performed in three situations:

    3) when a base class or a non-static data member is not mentioned in a constructor initializer list and that constructor is called.

    Value initialization is performed in three situations:

    3,7) when a non-static data member or a base class is initialized using a member initializer with an empty pair of parentheses or braces (since C++11)

    Note that the C++11 part belongs with the or braces, not with the entire paragraph.

    And:

    To value-initialize an object of type T means:
    — if T is an array type, then each element is value-initialized;
    — otherwise, the object is zero-initialized

    So in C++11 default-initialization does not zero-initialize members but value-initialization does.

提交回复
热议问题