Copy constructor

tutorial and example
tutorial and example

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 of value of data member of one object to another object.

Syntax:

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

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

C++ Copy Constructor Example

Output: