Copy Constructor Example in C++ Programming with Source Code
#include<iostream.h>
#include<conio.h>
//Def: Copy Constructor Example.
class first
{
private:
int a,b;
public:
first()
{
a=0;
b=0;
}
first (first &c)
{
a=c.a;
b=c.b;
}
void display()
{
cout<<"\nThe Value of A=>"<<a<<endl;
cout<<"\nThe Value of B=>"<<b<<endl;
}
};
void main()
{
clrscr();
first a1;
first a2(a1);
a1.display();
a2.display();
getch();
}
#include<conio.h>
//Def: Copy Constructor Example.
class first
{
private:
int a,b;
public:
first()
{
a=0;
b=0;
}
first (first &c)
{
a=c.a;
b=c.b;
}
void display()
{
cout<<"\nThe Value of A=>"<<a<<endl;
cout<<"\nThe Value of B=>"<<b<<endl;
}
};
void main()
{
clrscr();
first a1;
first a2(a1);
a1.display();
a2.display();
getch();
}
Copy Constructor Example in C++ Programming with Source Code
Reviewed by Unknown
on
5:56:00 PM
Rating:
No comments: