What are primitive types default-initialized to in C++?

前端 未结 6 1930
无人及你
无人及你 2020-11-27 14:05

When I use an initialization list:

struct Struct {
    Struct() : memberVariable() {}
    int memberVariable;
};

the primitive type (

6条回答
  •  春和景丽
    2020-11-27 14:24

    It depends on how you instantiate a class, if you use ClassName() the POD classes are default initialized to zero for non POD class default constructor is called but if you use ClassName, without the parentheses no default initialization takes place.

提交回复
热议问题