C + + Union usage note

Source: Internet
Author: User
Union is far less likely to be used when we write programs than structs. So we often do not care about her, we know that he is using memory multiplexing technology. At the same moment, he can only have one member value. C, we can include structs in the union, but it's not the same in C + +. Especially when we use the class in the Union. For example, when using to CString, you will find that the program will error. The question made me very confused, and after reading some information I finally understood what was going on. The Union object is not constructed when it is created, but simply allocates memory. When we include a class in the Union, the class is going to be constructed, and the Union is not constructed, so that the resulting result, the object of the class is not created. This will cause an error.

C + + Union usage note

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.