Static Member Functions in C++

Like static member variable, we can also have static member functions. A member function that is declared static just place a static keyword before the function header.


static long timediff();

Characteristics of Static Member function:

  1. Static member functions are associated with a class, not with any object.
  2. They can be invoked using class name, not object.
  3. They can access only static members of the class.
  4. They cannot be virtual.
  5. They cannot be declared as constant or volatile.
  6. A static member function can be called, even when a class is not instantiated.   
  7. There cannot be static and non-static version of the same function.
  8. A static member function does not have this pointer.


class test
	int code;
	static int count; // static member variable
	void set(void)
	void showcode(void)
		cout<<”object member : “<<code<<end;
	static void showcount(void)

Related posts