Wednesday, 30 January 2013

Copy Constructor


By on 02:23

Copy Constructor:-Copy Constructor are the constructor that have one argument of the object of same class.Copy constructor is used in c ++,java,c#(c sharp) etc.

Example of Copy Constructors(in c++):-

#include<iostream.h>
#include<conio.h>
class number
{
int a,b;
public:
number(int x,int y)     
{
a=x;
b=y;
}
number(number &n)    //copy constructor 
{
a=m;
b=m.b;
}
void display()
{
cout<<a<<b;
}};
void main()
{
number m(20,49);
m.display();
number m1(m);
m1.display();
getch();
}



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...