Wednesday 22 February 2012

Explain the concept of copy constructor? | Constructor in C++

a Copy constructor is a special type of parameterized constructor. It copies one object to another. It is called when an object is created and equated to an existing object at the same time. An existing object is passed as a parameter to it.
For Example:
A A1; //default constructor called.
A A2=A1; //copy constructor called.
(or)
A A2(A1) //copy constructor called.
(or)
A *Aptr= new A(A1); //copy constructor called.