Static Integers Tutorial in C++


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

class Counter
{
      private:
      static int count;
      public:
      Counter()
      {
            count++;
      }

      void display();
};

int Counter::count;

void Counter::display()
{
      cout<<count;
}
//int Counter::count;
void main(void)
{
      clrscr();
      Counter o1,o2,o3,o4;
      cout << "Objects in existence: ";
      o4.display();
      getch();
}
Custom Search