Automatic Default Constructor

If we don’t provide any custom constructors, the C++ compiler provides an automatic default constructor for our class for free.

The automatic default constructor will only initialize all member variables to their default values.

Custom default constructor

The simplest constructor we can provide is a custom default constructor that specifies the state of the object when the object is constructed. We define one by creating:

Cube.h

Cube has no return type!

Cube has no return type!

Cube.cpp

Untitled

main.cpp

Untitled

Custom (non-default) Constructors

We can also specify custom, non-default constructors that require client code to supply arguments

Cube::Cube(double length)
// one-argument ctor specifying initial length

Untitled

Custom Copy Constructor

A custom copy constructor is: