class myClass
{
public:
int someInt;
static myClass subObject; // infinite loop?
};
Wouldn't it cause an infinite loop of object creation? I mean, when you declare a myClass object, it would create a static myClass object, which would create a static myClass object, which would...etc?
And how could code like this be useful in real world coding?
"static" attributes and methods aren't part of an object. Think of them as class attributes. They will not be instantiated on object creation. So they exists only once while non-static attributes do exist as a separate instance for each object.
"static" attributes are helpful f.e. to realize singletons, to define constants or initialization purposes.