Advertisement
TechOPGOHIL

Untitled

Dec 3rd, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. //write a program to perform copy constructor with implisit and explisit
  2. #include<iostream.h>
  3. #include<conio.h>
  4. class ombha
  5. {
  6.     int a,b;
  7.     public:
  8.     ombha()      // default constructor code
  9.     {
  10.         a=10;
  11.         b=30;
  12.     }
  13.     ombha (ombha &tmp)        // copy constructor code
  14.     {
  15.         a=tmp.a;
  16.         b=tmp.b;
  17.     }
  18.     void display()
  19.     {
  20.         cout<<"A = "<<a<<endl;
  21.         cout<<"B ="<<b<<endl;
  22.     }
  23. };
  24. void main ()
  25. {
  26.     clrscr();
  27.     cout<<"\nDefault Consteructure Called\n";
  28.     ombha o;
  29.     o.display();
  30.     cout<<"\nCopy Consteructor Called With Implisit\n";
  31.     ombha o2;     // there are 2 type of copy other constructor 1 one is this
  32.     o2=o;
  33.     o2.display();
  34.     cout<<"\nCopy Consteructor Called With explisit\n";
  35.     ombha o3 = ombha (o); // there are 2 type of copy other constructor 2 one is this
  36.     o3.display();
  37.     getch();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement