Copy Constructor vs. Assignment

A copy constructor creates a new object (constructor).

An assignment operator assigns a value to an existing object.

Automatic Assignment Operator

If an assignment operator is not provided, the C++ compiler provides an automatic assignment operator.

The automatic assignment operator will copy the contents of all member variables.

Custom Assignment Operator

A custom assignment operator is:

Cube & Cube::operator=(const Cube & obj)

The goal of the custom assignment operator is to assign the content in object to the instance of the object being called.

1. Custom default constructor 2. Custom copy constructor 3. Custom assignment operator

  1. Custom default constructor 2. Custom copy constructor 3. Custom assignment operator

Untitled