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;
}

Comments

Popular posts from this blog

Dynamic Memory allocation in C++ for 1d, 2d and 3d array

Write Your Own String Class:

Printing the odd and even no using Pthread