Construction
Learn about the construction of structs in this lesson.
We'll cover the following...
We'll cover the following...
Let’s continue our discussion from the previous lesson. Consider the following code:
The first three lines of main() are about constructing the periodStart object, and the next three lines are about constructing the periodDuration object. In every three lines of code first, an object is being defined and then its hour and minute values are being set.
In order for a variable to be used in a safe way, that variable must first be constructed in a consistent state. Because construction is so common, there is a special construction syntax for struct objects:
The values are automatically assigned to the members in the order that they are specified: Because hour is defined first in the ...