Basically all functions are actually “static” because the code of the function only exist once in the whole program. The difference is that member functions which “belong” to an instance of the class have an additional invisible parameter: “this”.
If you call a member function you actually just call the function and the compiler implicitly passes the reference of the instance.
Static functions are functions without that implicit parameter, that’s all.
If you use C# you might know “extension methods”. They actually are implemented as member functions actually wotk.
For example:
//C#
public static class Vector3Extensions
{
public static Vector3 Scaled(this Vector3 aThis, Vector3 aScale)
{
return Vector3.Scale(aThis, aScale);
}
}
this extension would allow this:
Vector3 myVec = new Vector3(2,4,8);
Vector3 result = myVec.Scaled(new Vector3(2,3,1));
// result will contain (4, 12, 8)
When Scaled is executed the actual “context” object will be passed as additional parameter.
Inside “real” member functions the compiler provides additional syntactic suggar. Since your function belongs to a class instance the compiler interprets all variables it don’t know as “this.varName”
A static class is simply a class with all its member variables/functions being static. If a static class has a function, that function is automatically static as well.
A static function does not require an instance of a class, similar to how a static variable does not either. Generally, it will only work with static variables of the same class or variables from other classes.