The difference between C and C + + struct

Source: Internet
Author: User

A struct is defined in C, and the typedef is usually used to alias the struct, for example:

1 struct Tagobject 2 {3     int weight; 4     int Price ; 5     int status; 6 }object;

Thus, when a variable is created with this custom data structure, it can be written like this:

1 OBJECT    objs;

And if it is not redefined with TypeDef, that is, by the original definition of the struct:

1  struct Tagobject 2 {3      int weight; 4      int Price ; 5      int status; 6 }object;

Thus, if you want to create a variable of this type, you need to define this:

1 struct tagobject    objs;

The essential reason is that the data type created is a struct tagobject, not a tagobject.

However, in C + + there is no need to define a TypeDef, struct and class The only difference is the default access level , which class is private and struct public .

The difference between C and C + + struct

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.