Like static member variables, we can also have static member functions. It has the following properties:
#include<iostream.h>
class test
{
int a;
static int b;
public:
void setdata()
{
- A static function can have access to only other static members declared in same class.
- A static member function can be called using the class name as follows
#include<iostream.h>
class test
{
int a;
static int b;
public:
void setdata()
{
a=b++;
}
static void showdata()
{ cout<< b; }
};
void main()
{
static void showdata()
{ cout<< b; }
};
void main()
{
text x1,x2;
x1.setdata();
x2.setdata();
test::showdata();
x1.setdata();
x2.setdata();
test::showdata();
}
Tags:
Cpp