Simple question, here: what is the difference between a static member function, i.e. a function that can be called without requiring an object to access it (simply using the class identifier), and a non-member function? Here, I am asking both conceptually and functionally.
Are non-member functions conceptually static?
static member functions can access private and protected sections of a class. Non-member functions cannot do that as default. They can do that only if a class grants them friendship.
Another point to consider is that name of the static member functions are in the scope of the class. Multiple classes can have static member functions with the same name without worrying about names conflicting.
I would like to append the answer of @R Sahu that overloaded operators may not be static functions of a class.:)
Also static functions themselves can be protected and private. So they can be inaccesible outside the class where they are declared or its derived classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With