STATIC

Home >> Sem 2 >> C++ programs >> STATIC

/* Write a program to demostrate the use of static variables in a class by
using it to count the number of objects created in program */
#include<iostream.h>
#include<conio.h>
class test
 {
    static int count;
   public:

      test()
       {
        count++;
        cout<<endl<<count<<" objects are created";
       }
     ~test()
       {
        cout<<"\n"<<count<<" object is Destroyed.";
        count--;
       }
 };
 int test::count;
 void main()
  {
   clrscr();

     test t1;
   // t1.show();

    test t2;
    test t3;
    test t4;
   getch();
  }