Direct initial examination, copy initial, value preliminary

Source: Internet
Author: User

List initial: Use curly braces to do a preliminary

Direct initial: Put parameters in parentheses to preliminary

Copy initial: Use = or the tired object as an initial parameter

Value initiation: The space opened in C + + enables value initialization by the type name of the space being initialized, followed by (), and the library type automatically enables value initialization for uninitialized variables.

1. When the variable is a built-in type, the value initialization is initialized with zero.

2. When the variable is a class type, the value initialization is initialized with the default constructor of the class.

3. When a variable is of class type and there is no default constructor, the initialization of the value requires the programmer to provide the initialization value.

By default, dynamically allocated objects are initialized by default, which means that the value of an object of a built-in type or combination of types is undefined, whereas a class-type object Initializes a default constructor, or a value is initialized on a dynamically allocated object, just a pair of empty parentheses followed by a type name.

In the default constructor of the composition , if it is a class object, the default constructor for the object is called, and if it is a built-in type, it is undefined.

#include <iostream>using namespacestd;classa{ Public:Private: A&operator=(Consta&); intA;};intMainintargcChar**argv) {A A,*PA =NewA (); return 0;}
a={a=-6589}    // did not give a preliminary *pa={a=0}        // built-in type 0 

Direct initial examination, copy initial, value preliminary

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.