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


when use initialization list:

struct struct {     struct() : membervariable() {}     int membervariable; }; 

the primitive type (int, bool, float, enum, pointer) member variable default-initialied. value gets implementation defined or same implementations?

you not correct. object not default-initialized value-initialized. , value well-defined

int = 0,  bool = false,  float = 0.0f,   enum = (enum type)0,  pointer = null pointer pointer member = null member pointer 

note 0 in range of values enumeration, if doesn't contain explicit enumerator vaue, it's safe initialize enumeration variable value.

in particular pointer data members, representation used in practice not all-zero bits. in so-called c++ itanium abi used @ least gcc , clang, pointer data members have all-one bits null representation.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -