C++ Programming Blog

 
 
 

Image

 #include<iostream.h>
 #include<conio.h>


 //-------------------------------  count  -------------------------------//


 class count
    {
       private:
        int count;

       public:
        count()     { count=0;  cout<<\"I am a constructor\"<<endl;    }
        void inc_count()  { count ++; }
        int get_count()  { return count; }
    };

 main( )
    {
       clrscr();

       count c1;
       count c2;

       cout<<\"c1 = \"<<c1.get_count()<<endl;
       cout<<\"c2 = \"<<c2.get_count()<<endl;

       c1.inc_count();
       c2.inc_count();
       c2.inc_count();

       cout<<\"c1 = \"<<c1.get_count()<<endl;
       cout<<\"c2 = \"<<c2.get_count()<<endl;

       getch();
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to illustrate the role of constructor in classes