CSE 100 Lecture Notes - Lecture 30: Local Variable, Member Variable
Document Summary
First value initializes first data member, second value initializes second data member, etc. Elements of an initialization list can be constants, variables, or expressions. {12, w, l/w + 1} // initialization list with 3 items. You can initialize just some members, but you cannot skip over members. Dimensions box2 = {12, , 3}; // illegal. You cannot omit a value for a data member without omitting values for all following members. It does not work on most modern compilers if the structure contains objects, e. g. like string objects. Using a constructor to initialize structure members. This is similar to a constructor for a class: The name is the same as the name of the struct. It is used to initialize data members. It is normally written inside the struct declaration. {length = l; width = w; height = h;} A structure can have another structure as a member. Use the dot operator multiple times to access fields of nested structures.