[001] First-recognized reference, 001 first-recognized reference
Reference is equivalent to another name for the object. This type references another type. The referenced identifier starts.
1 int val = 180; 2 int & reference = val; // refVal points to ival3 int & mistake; // error: the reference must be initialized
The above example shows that the initial value is usuallyCopyTo the new object. When defining a reference, the program refers to the reference and its initial value.BindTogether. Once the initialization of the reference is complete, the binding link will always exist. Therefore, the reference mustInitialization.
Note,AliasIt is not an object.
1 int I = 10; 2 int & refi = I; 3 refi = 1; // assign 1 to i4 int a = refi; // equivalent to making a = I
The initial value must be an object, and the referenced type must be exactly the same as the object. Therefore:
1 int & ref = 0; // Error 2 double a = 1.12; 3 int & refa = a; // Error