### Copying Class Objects

You can copy one class object to another object of the same type by either assignment or initialization.

Copy by assignment is implemented with an assignment operator function. If you do not define the assignment operator, it is defined as memberwise assignment.

Copy by initialization is implemented with a copy constructor. If you do not define a copy constructor, it is defined as memberwise initialization of members of its class.

Memberwise assignment and memberwise initialization mean that, if a class has a member that is a class object, the assignment operator and copy constructor of that class object are used to implement assignment and initialization of the member.

Restrictions:

A default assignment operator cannot be generated for a class that has:

- A nonstatic constant or reference data member
- A nonstatic data member or base class whose assignment operator is not accessible
- A nonstatic data member or base class with no assignment operator and for which a default assignment operator cannot be generated .

A default copy constructor cannot be generated for a class that has:

- A nonstatic data member or base class whose copy constructor is not accessible
- A nonstatic data member or base class with no copy constructor and for which a default copy constructor cannot be generated.

Constructors and Destructors Overview

Copy by Assignment
Copy by Initialization
Constructors
Overloaded Assignment