Thursday, October 16, 2014

Write a program for use of static member function in c++

Prog 26: Write a program for  use of static member function.

#include<iostream.h>

  #include<conio.h>

  class item

  {

public:

static int count;

  int no;

void getdata(int a)

  {

no=a;

  count++;

  }

  static void display()

  {

  cout<<"\n count  ="<<count;

  }

  };

  int item::count;

  void main()

  {

  clrscr(); item A,B;  A.getdata(100); item :: display();  B.getdata(200); item :: display();  getch();

  }

Output:

count =1 count =2


No comments: