Summary
Let’s look at a summary of the concepts covered in this chapter.
We'll cover the following
Chapter summary
-
Constructor
(this)
is for preparing objects for use. The compiler-generated default constructor is sufficient in most cases. -
The behavior of the default constructor may not be changed in structs;
static opCall
can be used instead. -
Single-parameter constructors can be used during type conversions by
to
andcast
. -
Destructor
(~this)
is for operations that must be executed when the lifetimes of objects end. -
Postblit
(this(this))
is for adjustments to the object after the automatic memberwise copy is made. -
Assignment operator
(opAssign)
is for changing the values of existing objects.
Get hands-on with 1400+ tech skills courses.