Suppose you declare static variables in your class.
eg
class Example
{
private:
int aVariable;
static int anotherVariable;
};
Example::anotherVariable = 0;
Now the property of the static Variable is that it doesn't belong to any particular instance of the class. It is shared by all the instances of the class. It exists even if there are no instances of the class.
Now suppose you would wish to access this variable. You could do that before creating any instances of the class. But how would you access it.
That is where static functions comes into play. With them you could access the static variable.
eg
class Example
{
public:
static int returnStaticVariable()
{
return anotherVariable;
}
private:
int aVariable;
static int anotherVariable;
};
You could call this static function with the Class Name, instead of instance.
eg
int main()
{
std::cout<<Example::returnStaticVariable();
}