|
To | Do this |
---|---|
Create a struct. | Use __value struct, followed by the name of the struct and the body in braces, followed by a semicolon. For example: __value struct Point3D { int x, y, z; }; |
Initialize struct members. | Create a constructor, which is a function that has the same name as the struct. For example: __value struct Point3D { int x, y, z; Point3D(int xVal, int yVal, int zVal) { x=xVal; y=yVal; z=zVal; } }; You can also use an aggregate initializer: Point3D p1 = { 10, 20, 30 }; |
Access struct members. | Use the dot notation. For example: p1.x = 10; myPerson.DOB.dd = 20; |
Create an enum. | Use __value enum, followed by the name of the enum and the body in braces, followed by a semicolon. For example: __value enum Seasons { Spring, Summer,Autumn, Winter }; |
Control the values used for enum members. | Assign values to the members in the enum definition. For example: __value enum Seasons { Spring=1, Summer, Autumn, Winter }; |
Base enums on other integer types. | Put a colon and the type name after the enum name. For example: __value enum Seasons : char { Spring, Summer, Autumn, Winter }; |
|