Monday, 24 June 2013

what is constructor in c++, constructor in c++


Constructor
                  A constructor is a special member function whose task is to initialized the  object
                  of its class,the constructor name is same as the class name. The constructor is
                  invoked whenever an object of its associated class is created.
                
                  A constructed is  decalred and defined as follows
                  
                class integer
                 {
                        int m, n;
                    public :
                          integer();
                };
               
               integer :: integer()       // constructor defined
               {
                        m =0; n =0;
               }  
                    
              when a class contains a constructor like the one defined above, it is guaranteed
              that an object created by the class  will be initialized  automatically, For Example ,
              the decalaration  integer int1;    // object int1 created

              Imp : constructor that accept no parameter is known as default parameter;
                           

0 comments:

Post a Comment