C++primer Notes Composite Type--citation

Source: Internet
Author: User

    • composite Types : Languages that are based on other types of definitions

There are two types of

    • Reference

    • Pointer

Declaration statement: A basic data type that consists of a list of declarators

    • Reference: A different name for an object

    • Reference type: Referencing a different type

int ival = 1024;int &refval = ival;              Refval points to Ival (another name for ival) int &refVal2; Error, reference must be initialized
    • General initialization variables: the initial values are copied to the newly created object

    • Definition reference: binds the reference with his initial value , rather than copying it to a reference. The initialization is complete, and the reference and initial values are bound together . Because the reference cannot be re-bound to another object, the reference must be initialized .


  1. References and aliases

    1. A reference is not an object, but it is just another name for an already existing object , and after the reference is defined, all operations are performed on the object to which it is bound.

      1. Refval = 2; Assigns 2 to the object that Refval points to, namely gives Ivalint II = Refval;
      2. Reference assignment: Assigns the value to the object to which it is bound.
      3. Gets the value of the reference: Gets the value on the object to which it is bound

      4. Use reference as initial value: reference the bound object as the initial value

    2. Correct: RefVal13 bound to the object bound to the Refval, is bound to the ival int &refval13 = Refval;        Initializes the variable iint i = Refval with the value of the Refval bound object; Correct: I was initialized to the value of ival
    3. The reference itself is not an object, so reference references cannot be defined.

  2. Definitions of references

    1. Allows a statement to define multiple references, each of which must start with &

    2. int i = 1024x768, i2 = 2048;            I and i2 are int int &r = i, r2 = i2;        R is a reference, bound together with I, R2 is intint i3 = 1024x768, &ri = i3;         I3 is Int,ri is a reference, bound together with i3 int &r3 = i3, &r4 = i2; R3 and R4 are all references

    3. In addition to the two exceptions described in 2.4.1 (55 pages) and 15.2.3 (534 pages), the other referenced types are strictly matched to the objects to which they are bound. A reference can only be bound on an object, not a literal value or the result of an expression, for reasons 2.4.1 detailed.

    4. int &refval4 = 10;double Dval = 3.14;int &REFVAL5 = dval;





This article is from the "Mount Sen" blog, please be sure to keep this source http://munson.blog.51cto.com/7358127/1739966

C++primer Notes Composite Type--citation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.