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
- #include <iostream>
- using namespace Std;
- struct Zoo_obj{
- string name;
- Union {
- unsigned int property;
- struct{ //plant
- unsigned int
- Hasleaf: 1,
- Hasflower: 1,
- Hastrunk: 1,
- Hasrattan: 1;
- };
- struct { //animal
- unsigned int
- Isbackbone: 1,
- Isovipara: 1,
- Haslags: 1,
- Haswing: 1;
- };
- };
- };
- int main(void)
- {
- Zoo_obj Peony = {"peony", 0};
- Zoo_obj Dog = {name:"Dog", 0};
- Dog. Haslags = true;
- /* zoo_obj Dog = {name:"Dog",property: 0};
- * Sorry, unimplemented: Non-trivial designated initializers
- * NOT supported
- */
- cout << peony. Name << "Hasleaf" << peony. Hasleaf < < Endl;
- cout << dog. Name << "Haslags" << dogHaslags << Endl;
- }
Output
- Peony Hasleaf 0
- Dog Haslags 1
Specified access like sake name is not supported. If an error is specified
- Sorry, unimplemented:non-trivial designated initializers not supported
C + + anonymous union,struct-Anonymous consortium and body