Tuesday, November 22, 2011

C and C++ Examples ( Static Function )


  /* PROGARAM TO IMPLEMENT USING STATIC FUNCTION */
#include"iostream.h"
/*using namespace std;*/
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number=a;
count++;
}
void getcount(void)
{
cout<<"count";
cout<<count<<"\n";
}
};
int item::count ;
int main()
{
item a,b,c;
a.getcount();
b.getcount();
c.getcount();
a.getdata(10);
b.getdata(20);
c.getdata(30);
cout<<"after reading data"<<"\n";
a.getcount();
b.getcount();
c.getcount();
return 0;
}

Output :

count0
count0
count0
after reading data
count3
count3
count3

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Vamshi krishnam raju | Bloggerized by Vamshi krishnam raju - Vamshi krishnam raju | Vamshi krishnam raju