When the object is created with a specific value, we say that the object is initialized.
The C + + language is initialized with equal sign =, and many people mistakenly think of it as an assignment, but the two are completely different. This concept is very important.
- Different ways of initializing
- Default initialization
The default initialization consists of direct initialization and not being initialized.
When initialized directly, the variable is assigned the default value. The default value is exactly what is determined by the variable type. In the case of classes, classes can control their own initialization.
The value of a variable that is not initialized is undefined.
That is, the use of curly braces for initialization.
If there is a risk of losing information when using the list initialization, the compiler will make an error.
Long Double 3.1415926 / /correct int// error
Initialization with an equal sign is called copy initialization.
For example: string s5 = "Hiya", hiya\n the literal value of \ n is omitted, the remainder is assigned to S5.
The initial method with parentheses.
C + + initialization (1)