latest Post

C + + part 6 (constructor - copy constructor )





So hey guys we are again back with a article of our series named as C+ + and if you are not seen our other articles of this series then you must see it before then read this one then you will understand this article easily .And don't be confused this is C+ + and the C series is also coming very soon so if you not then red them also .
So here we start.............................................

COPY CONSTRUCTOR

It is a type of constructor which creates automatically or manually an object same as or by read an object of the same class .
To copy and object there is an argument to the function .
The object which has to be copied is to be of same type .

lets jump on the code.......................................

#include<iostream.h>
#include<conio.h>
class abc
               {
                              int i ;
                              public :
                                                  abc(int m)
                                                  { 
                                                           i=m; 
                                                  }
                                                   abc (abc &m)
                                                  { 
                                                           i=m.i;  
                                                  }
                                                  
                                                  void display ( )
                                                  {
                                                           cout<<"\n i="<<i<<endl;
                                                  }
               } ;
void main ( )
{
                 abc a(20) ;
                 abc b=a ;
                 a.display ( ) ;
                 b.display ( ) ;   
                 getch ( ) ;
}
Hence , the code is finished .
So if any problem with articles please write in the comment box or contact us by filling the contact form in contact us.

About hack guru

hack guru
Recommended Posts × +

0 comments:

Post a Comment