-->

static members in oop, classes, static member function etc.

 

When you use static for a class member(data member and method), it means that the item belongs to the class itself, not to any particular object created from that class.

A static method in C++ isn't linked to any object, so it doesn't use the "this" pointer.

A static function in a class can't directly call non-static methods because it doesn't have access to the "this" pointer needed for non-static methods. However, non-static methods can be called static methods without any issues.






Static member variables are shared among all instances of a class. This means they are not tied to any specific object but belong to the class itself. They are useful for storing data that needs to be shared across all instances of the class. You have to define static data members outside the class.


Static member functions can be called directly using the class name, without needing to create an object. It’s also possible called using object. 

In C++, static member variables must be defined outside the class in order to allocate memory for them. When a static member variable is declared inside a class, it is only declared and not defined. This means that memory is not allocated for the static member variable at that point.

The definition of the static member variable outside the class provides the memory allocation for the variable. It tells the compiler that memory should be allocated for the static member variable separately from instances of the class.

Static and global objects are created before the main function starts executing and are destroyed after the main function finishes.