Copy constructor

C++ Copy Constructor

A copy constructor is a member function which initializes an object using another object of the same class.

Copy constructor takes an object as argument. It is used to copy the value of data member of one object to another object.

Syntax:

Declaration and initialization of one object to another object are done as:

In the above statement, the value of one object (obj1) is copied into another object (obj2).

C++ Copy Constructor Example

Output:

Leave a Comment