Static member functions in C++: Examples and limitations

Static member functions are used to pre-initialize private static data before creating any object.

For Example:

#include <iostream>

using namespace std;

class test {

static int a;


static void init(int b) {a = b;}

void show() {cout << a;}


int test::a;

int main()



test b;;

return 0;


Limitations of static member functions:

1) It doesn’t have a “this” pointer.

2) A static member function cannot directly refer to static members.

3) Same function can’t have both static and non static types.

4) It can’t be virtual.

5) A static member function can’t be declared as const or volatile.

Leave a Reply