Q3 copy constructor program .
#include<iostream>
using namespace std;
class A
{
int x, y;
public :
A():x(20),y(40)
{
}
A(const A &ob){
x=ob.x;
y=ob.y;
}
void show()
{
cout<<x<<endl<<y<<endl;
}
};
int main()
{
A obj1;
A obj2=obj1; //copy constructor is called .
obj2.show();
return 0;
}
using namespace std;
class A
{
int x, y;
public :
A():x(20),y(40)
{
}
A(const A &ob){
x=ob.x;
y=ob.y;
}
void show()
{
cout<<x<<endl<<y<<endl;
}
};
int main()
{
A obj1;
A obj2=obj1; //copy constructor is called .
obj2.show();
return 0;
}
Comments
Post a Comment