C + + Anonymous union,struct--Anonymous consortium and body

Source: Internet
Author: User

C + + Anonymous union,struct--Anonymous consortium and body

The basic usage of the structure and the consortium is not to be mentioned, but only for the information they visit when they are anonymous. If the token is different, you can access it directly across tiers. Example

  1. #include <iostream>
  2. using namespace Std;
  3. struct Zoo_obj{
  4. string name;
  5. Union {
  6. unsigned int property;
  7. struct{ //plant
  8. unsigned int
  9. Hasleaf: 1,
  10. Hasflower: 1,
  11. Hastrunk: 1,
  12. Hasrattan: 1;
  13. };
  14. struct { //animal
  15. unsigned int
  16. Isbackbone: 1,
  17. Isovipara: 1,
  18. Haslags: 1,
  19. Haswing: 1;
  20. };
  21. };
  22. };
  23. int main(void)
  24. {
  25. Zoo_obj Peony = {"peony", 0};
  26. Zoo_obj Dog = {name:"Dog", 0};
  27. Dog. Haslags = true;
  28. /* zoo_obj Dog = {name:"Dog",property: 0};
  29. * Sorry, unimplemented: Non-trivial designated initializers
  30. * NOT supported
  31. */
  32. cout << peony. Name << "Hasleaf" << peony. Hasleaf < < Endl;
  33. cout << dog. Name << "Haslags" << dogHaslags << Endl;
  34. }
Output
    1. Peony Hasleaf 0
    2. Dog Haslags 1
Specified access like sake name is not supported. If an error is specified
    1. Sorry, unimplemented:non-trivial designated initializers not supported

C + + anonymous union,struct-Anonymous consortium and body

Related Article

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.