Hello Friends,
What is the advantage of defining a function as Static as a class member.
Like
Class Name
{
public :
static void fun()
}
so what is the significance of defining a function as static.
Static member functions are associated with the class, not with an object. One can use static member functions, whenever you have functionality (or data) that is not needed to be copied to all objects (e.g. since it is the same).
A simple example would be the number of objects you have made from a class. This information would be stored to a static class member, since is is the same for all objects.
Another advantage concerns the scope. Your fun() function in the example above is identified via
and can thus not be confused with other function which may have the same name. This can be helpful in situations where the compiler would otherwise have problems to identify which function you want to call (think of template arguments as an example).