Sunday, November 6, 2011

Copy constructor

Out put of the program
// Copy constructor
# include<iostream>
# include<conio.h>

using namespace std;
class code
{
int id;
public:
code(){}    //Blank constructor
code(int a){
id=a;
}
code(code & x){
id=x.id;
}
int display(){
     return(id);
}
};

main(){

code A(100);    // object a is created and initilized
code B(A);    // copy constructor called
code C=A;
code D;
D=A;

cout<<endl<<"id of A:"<<A.display();
cout<<endl<<"id of B:"<<B.display();
cout<<endl<<"id of C:"<<C.display();
cout<<endl<<"id of D:"<<D.display();
getch();
return 0;
}

No comments:

Post a Comment