Cpp : Static Member 4

Static member function

* Member functions can be declared as static using the keyword “static”.
* Keyword static is used while giving the declaration of the function in the class.
* A static member function belongs to all the objects of the class.
* A static member function can manipulate only static data elements of the class.
* “this” pointer is not available for static member functions.
* Keyword static is not used while giving the definition of the function.
* Static member functions can be directly invoked using the name of the class i.e. we do not require an object of the class to invoke a static member function.

Syntax:
classname::staticmemberfunction();

Class sample
{
private:
static int a;
int roll;
char name[20];
public:
void read();
static void show();
};

Calling/invoking a static member function

Syntax:
Classname::staticmemberfunction();
Sample::show();