previous | start | next

## Automatic Memory Management

- The purpose of `operator=` is to set an existing object equal to another object.
- Use of `=` for construction is not always appropriate.
- Example: Here, the pointer `dept.receptionist` is set to a random value. The operator will try to delete the receptionist causing an error.

  >     Department dept = qc;

- The copy constructor defines how to construct an object of a class as a copy of another object of the same class.

  >     Department dept(qc)

- If you don't define a copy constructor, then the compiler provides a version that simply copies the corresponding data fields of the existing object.
- This version of the copy constructor is still inappropriate, leading to the same kind of errors as the default version of the assignment operator.

previous | start | next