[英]Why is Circular reference in struct of instance type not allowed but circular reference of static type allowed?
為什么我們可以在struct中使用靜態循環引用而不是實例類型循環引用?
struct C
{
//following line is not allowed. Compile time error.
// it's a non static circular reference.
public C c1;
//But this line compiles fine.
//static circular reference.
public static C c2;
}
非靜態引用失敗是因為您試圖使結構成為其自身的一部分,從而導致循環引用。
靜態聲明是有效的,因為c2
不是結構本身的一部分; 無論何時聲明例如C foo
, c2
都不會影響foo
的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.