Saturday, November 19, 2011

C and C++ Examples ( Copy Constructor )


   /*PROGRAM TO IMPLEMENT COPY CONSTRUCTOR*/
#include"iostream.h"
class code
{
int id;
public:
code(){}
code(int a){id=a;}
code(code &x)
{
id=x.id;
}
void display(void)
{
cout<<id;
}
};
int main()
{
code A(150);
code B(A);
code C=A;
code D;
D=A;
cout<<"\n id of A: ";A.display();
cout<<"\n id of B: ";B.display();
cout<<"\n id of C: ";C.display();
cout<<"\n id of D: ";D.display();
return 0;
}

Output :

 id of A: 150
 id of B: 150
 id of C: 150
 id of D: 150

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Vamshi krishnam raju | Bloggerized by Vamshi krishnam raju - Vamshi krishnam raju | Vamshi krishnam raju