by Dinesh Thakur Category: Classes in C++

 

#include<iostream.h>

#include<conio.h>
class Increment
{
         private:
         int count;
         public:
         //*****Member Function Definitions******
               Increment( ) // Default Constructor
           {
                       count = 0 ;
               }
                   Increment(int C) // Constructor with Argument
               {
                   count = C ;
               }
                   Increment operator ++ ( ) // Operator Function Definition
               {
                   count++;
                   return Increment(count);
               }
             void display(void) // Function for displaying the output
               {
                   cout << count << endl ;
               }
}; // End of the class definition
              void main(void)
     {
              Increment l1,l2(5),l3,l4 ;
              clrscr();
              cout <<"\n Before Activating the Operator ++( )\n" ;
              cout << "l1=";
              l1.display( );
              cout << "l2= ";
              l2.display( );
              ++l1 ; // l1and l2are incremented
              l2++ ;
              cout << "\n After Activating the Operator ++(.)\n" ;
              cout << "l1= ";
              l1.display( );
              cout << "l2= " ;
              l2.display( ) ;
              l3= ++l1 ; /* Here, the objects 11and 12are incremented again and their 14=12++; values are assigned to the objects 13and 14respectively */
              cout << "l3= ";
              l3.display( ) ;
              cout << "l4= ";
              l4.display( ) ;
              getch();
     }

overloading-the-increment-operator-(++)-with-return-value

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article