#include<iostream.h>
using namespace std;
class code
{
int id;
public:
code(){};
code(int a){id=a;}
code(code &x) // copy constructor.
{
id=x.id; //copy in the value.
}
void display(void)
{
cout << id;
}
};
int main()
{
code A(100); // object A is created & initialized.
code B(A); //copy constructor called.
code C = A; // copy constructor called again.
code D;
D = A; // copy constructor not called.
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:100
id of B:100
id of C:100
id of D:100
Tag

Related Post

Leave a Reply