1.

What is a copy constructor?

Answer»

A copy CONSTRUCTOR is a member function that initializes an OBJECT using another object of the same class.

Example-

class A{int x,y;A(int x, int y){ this->x=x; this->y=y;}};int main(){A A1(2,3);A a2=a1; //DEFAULT copy constructor is calledreturn 0;}

We can define our copy constructor. If we don’t define a copy constructor then the default copy constructor is called.



Discussion

No Comment Found