CSE 100 Lecture Notes - Lecture 30: Local Variable, Member Variable

75 views3 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents