solidity智慧合約[40]-memory屬性
阿新 • • 發佈:2018-11-26
memory引入
函式中結構體變數預設是是storage型別
下面是一段錯誤的程式碼,錯誤的原因在於,init函式中,student s 預設會加上storage的屬性,但是storage屬性必須要引用storage空間中的狀態變數。但是例項化的student(100,“jackson”)並不在storage中。
1 |
struct student{ |
因此,正確的做法是,必須要變數的初始化放在memory空間中。加上了memory屬性的變數,意味著變數儲存在memory的空間中。
1 |
struct student{ |
本文連結: https://dreamerjonson.com/2018/11/23/solidity-40-memory/
版權宣告: 本部落格所有文章除特別宣告外,均採用 CC BY 4.0 CN協議 許可協議。轉載請註明出處!