A static member function can have access to only other static members declared in the same class.
A static member function can be called by using its class name.
class_name::function_name( );
A static member function can not be virtual.
There should not be member function does not have 'this' pointer.
Write a program to demonstrate static member function.
#include<iostream.h>
#include<conio.h>
class test
{
int code;
static int count;
public:
void setdata( )
{
code=++count;
}
void show( )
{
cout<<"\n\n\tObject Number--->"<<code<<endl;
}
static void showcount( )
{
cout<<"\n\n\tCount is--->"<<count<<endl;
}
};
int test::count;
void main( )
{
test t1,t2,t3;
clrscr( );
t1.setdata( );
t2.setdata( );
test::showcount( );
t3.setdata( );
test::showcount( );
t1.show( );
t2.show( );
t3.show( );
getch( );
}
Output:-
Count is--->2
Count is--->3
Object Number--->1
Object Number--->2
Object Number--->3