Why is the Circular reference in the instance type structure not allowed, but the circular reference of the static type is allowed?

why can we have a static circular reference in a struct, but not a circular reference of instance type?

struct C { //following line is not allowed. Compile time error. // it a non static circular reference. public C c1; //But this line compiles fine. //static circular reference. public static C c2; } 
+6
source share
1 answer

A non-static link fails because you are trying to make the structure a part of yourself, which results in a circular link.

A static declaration works because c2 not part of the structure itself; when you state, for example. C foo , c2 does not affect the size of foo .

+6
source

All Articles