C + + notes continued

Source: Internet
Author: User

<center>c++ Note </center>1.c++ has only 2 variables initialized
    • Direct initialization: Use parentheses, int a (10);
    • Replication initialization: Use of =,int a=10; (object's copy constructor)
2.cin and Getline Read string
    • CIN read-in string separated by a space
    • Getline (Cin,line) reads the string with ' \ n ' as split
3. Function pointers

BOOL lencom (void);
typedef BOOL (*FUN) (void);
Fun PF1 = lencom;
Fun PF1 = &lencom; Independent functions are equivalent to using function names directly in front of &.
member functions must use &

4. Default constructors
    • Default constructor invocation timing: When an object is defined, the default constructor is called whenever no initialization is provided.
    • Default constructor for class: If a class defines only one constructor, the compiler will no longer automatically generate a default constructor
    • Custom default constructor: The parameterless constructor is the default constructor for the class.
    • Use the default constructor:

      Sales_item myobj (); #error declare a function rather than a defined object;
      Sales_item myobj; #正确, call the default constructor
      Sales_item Myobj=sales_item (); #正确, copy Assignment

5. Copy Constructors
    • Timing: When initializing a newly defined object with an object of the same type, the copy constructor is used explicitly, when an object of that type is passed to a function or an object of that type is returned from a function, a copy constructor is implicitly used, an element in the sequential container is initialized, and an array element is initialized based on the element initializer list. For example, the procedure for Vector<string>svec (5) is to initialize the Svec with a temporary value that the compiler first uses the default constructor of string, and then use the copy constructor to copy the temporary values to each element of Svec.
    • Default copy constructor: If the class does not have a copy constructor, the compiler always synthesizes a copy constructor for that class. The behavior of the default constructor for the composition is to perform a member-by- instance initialization, initializing the new object to a copy of the original object , that is, the non-static members are exactly the same.
    • Prohibit replication use the private adornment copy constructor to suppress replication

C + + notes continued

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.