+1 vote
in Class 12 by kratos

What is a copy constructor? Illustrate with a suitable C++ example.

1 Answer

+4 votes
by kratos
 
Best answer

A copy constructor is an overloaded constructor in which an object of the same class is passed as reference parameter.

class X

{ int a;

public:

X()

{

a=0;

}

X(X &ob) //copy constructor

{

a=ob.a;

}

};

...