COPY CONSTRUCTOR


class code { int id; public: code(){} //constructor code(int a){id=a} //constructor again code(code&x) { id=x.id; } void display(void) { cout<<id; } }; int main() { code A(100); code B(A); code C= A; code D; D=A; cout<< id of A:";A.display(); cout<< id of B:";B.display(); cout<< id of C:";C.display(); cout<< id of D:";D.display(); retrun 0; }
OUTPUT:
         id of A:100;
         id of B:100;
         id of C:100;
         id of D:100;

No comments:

Post a Comment