C + + composite data structure types

Source: Internet
Author: User

A struct struct:

struct Name {
Type var1;
Type var2;
....
} ;

A data structure that combines several basic types of structures to form.

Initialization method:
struct name var_name = {Value_list};

Two common body Union:

Union name {
Type var1;
Type var2;
....
};

All data structure types in a common body use the same address, which is typically combined with structs.

struct Name {
Type var1;
Type var2;
Union {
Type VAR3;
Type VAR4;
};
};

This creates an anonymous consortium.

Three enum types:
Enum name {var_list};
The first variable in the enumeration type is assigned a value of 0, and the subsequent value of the variable is added in turn

Other implementations of the four array types:

Apart from the traditional method of declaring arrays in C, there are two other ways in C + + that have the same effect.

(1) Use <vector> header file

                vector<typename> vt (n_elem) ;                如果说 size为0 , 那么后面的小括号部分可以抛弃。(2)   使用<array> 头文件                array<typename,n_elem> ai = { value_list };                其中的array可以在两者之间直接赋值,即                array_a    =    array_b ;

C + + composite data structure types

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.