C++ Programming/Programming Languages/C++/Code/Keywords/static/Member Function

static member function
Member functions or variables declared static are shared between all instances of an object type. Meaning that only one copy of the member function or variable does exists for any object type.

When used in a class function member, the function does not take an instantiation as an implicit parameter, instead behaving like a free function. This means that static class functions can be called without creating instances of the class:
 * member functions callable without an object

Named constructors
Named constructors are a good example of using static member functions. Named constructors is the name given to functions used to create an object of a class without (directly) using its constructors. This might be used for the following:


 * 1) To circumvent the restriction that constructors can be overloaded only if their signatures differ.
 * 2) Making the class non-inheritable by making the constructors private.
 * 3) Preventing stack allocation by making constructors private

Declare a static member function that uses a private constructor to create the object and return it. (It could also return a pointer or a reference but this complication seems useless, and turns this into the factory pattern rather than a conventional named constructor.)

Here's an example for a class that stores a temperature that can be specified in any of the different temperature scales.