PROGRAM TO IMPLEMENT COPY CONSTRUCTOR

/*PROGRAM TO IMPLEMENT COPY CONSTRUCTOR*/

#include<conio.h>

#include<iostream.h>

class abc

{

int a,b,sum;

public:

abc()

{

cout<<“Enter a: “;

cin>>a;

cout<<“Enter b: “;

cin>>b;

}

abc(abc &m)

{

a=m.a;

b=m.b;

cout<<“a= “<<a<<endl;

cout<<“b= “<<b<<endl;

}

};

void main()

{

clrscr();

cout<<“Default constructor is invoked:”<<endl;

abc a1;

cout<<“Copy constructor is invoked:”<<endl;

abc a2(a1);

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *