C++ program – illustrate the static member function

by Nideesh C on April 14, 2011 · 0 comments

in C++




#include<iostream.h>
#include<conio.h>
 
class test
{
	int code;
	static int count;
	public :
		void setcode(void)
		{
			code= ++count;
		}
		void showcode(void)
		{
			cout<<"object number"<<code<<endl;
		}
		static void showcount(void)
		{
			cout<<"count"<<count<<endl;
		}
};
int test::count;
 
int main()
{
	clrscr();
	test t1,t2;
	t1.setcode();
	t2.setcode();
	test::showcount();
	test t3;
	t3.setcode();
test::showcount();
	t1.showcode();
	t2.showcode();
	t3.showcode();
	getch();
	return(1);
}

OUTPUT

 Count 2
 Count 3
 Object number 1
 Object number 2
 Object number 3



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C++ program using class – To multiply by 10 to every member of a list
  2. C++ program to implement Heap sort Algorithm
  3. C program to illustrate the concept of unions
  4. Sample – check if a number is prime
  5. C++ program to implement Selection sort using class

Leave a Comment

Previous post:

Next post: