Why is value initialization called like this?

I really don’t understand why someone would call a specific form of initialization initialization. It looks like it initializes the object, giving it a value ... but what initialization does in general and the name does not tell you anything about what value it will use to initialize.

+5
source share
1 answer

Boost value_init write-up provides a fairly detailed history of value initialization, it turned out to be standard from defect report 178: more about value initialization , and it seems the term obtained from defect report 35: Default definition initialization . Despite the fact that none of these documents gives the correct origin for giving some good ideas, he says:

The first technical fix for the C ++ standard (TC1), whose project was published to the public in November 2001, introduced Core Problem 178 (of course, from many other issues).

A new concept of value initialization was introduced in this problem (it also corrected the formulation of zero initialization). Informally, default initialization initialization is similar to default initialization exception, in some cases non-static data elements and base class subelements are also initialized by value. The difference is that an object that is initialized with a value will not (or at least are less likely to have) undefined values ​​for the data members and base class sub-objects; unlike when the object is built by default. (see Core Issue 178 for regulatory description).

To indicate the initialization of the value of an object, we need to use an initializer with an empty set :().

and initializing a value is less likely to leave an object with an undefined value compared to default initialization.

+7
source

Source: https://habr.com/ru/post/1201689/


All Articles