1.

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

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;

}

};



Discussion

No Comment Found

Related InterviewSolutions