Static Member Function and its characteristics
We can define the class member function as static with the help of a static keyword which makes the class member function independent of any particular object.
A static member function may be called even though no object in the class exists and the static functions are accessible using only the class name and the scope resolution operator (::).
A static member function may only access static data member, other static member functions and any other functions outside the class.
The static member features have a class scope and they do not have access to that class pointer.
Example Program:
#include <iostream> using namespace std; class Item { static int count; public: static void display() { cout<<"Count = "<< ++count<<endl; } }; int Item::count; int main() { Item::display(); Item::display(); return 0; }
Output:
