Compiler-Generated Constructor

Get introduced to the compiler-generated automatic constructor and the use of this keyword.

We'll cover the following

Compiler-generated constructor

All of the structs that we have seen so far take advantage of a constructor that has been generated automatically by the compiler. The automatic constructor assigns the parameter values to the members in the order that they are specified.

As you will remember from the structs chapter, the initial values for the trailing members need not be specified. The members that are not specified get initialized by the .init value of their respective types. The .init values of a member could be provided during the definition of that member after the = operator:

svg viewer

Get hands-on with 1200+ tech skills courses.