Friday, 5 July 2013

can we overload pre increment ++ operator | how to overload operator

yes  we can overload  , this we can do by defining the function() inside the class, this we can overload by two method , in those two one is known as pre increment  operator overloading and another is post increment  overloading method.

Example  :
             
     class sample
      {
                // code

              public:
         
                   sample operator++() // pre-increment
                   {
                           // code;
                   }
               
                   sample operator++(int ) // post increment
                   {
                            // code;
                   }
     };
         
      Note that if the post increment ++ operator is not defined then for  both ++a and a++  the   pre-increment ++ operator function gets called vice-versa is however not true ;
       



0 comments:

Post a Comment