在solidity語言中
參考型別修飾符(參考型別為存盤空間不固定的數值型別)
memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等...
memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體
calldata 僅適用于方法傳參,修飾該變數的值不能修改
storage 僅適用于方法體內,而且它的指標必須指向鏈上資料,使用完,鏈上資料將保存最新狀態
常量修飾符
constant 編譯前已經確定,編譯后不能再修改常量的值
constant 它不是狀態變數,所以它不儲存在插槽(Slot)里面,獲取該常量的方法修飾必須是Pure,而不是View
immutable 它是狀態變數,所以它儲存在插槽(Slot)里,獲取該變數的方法修飾必須是View,而不是Pure
immutable 必須在建構式里面賦值,之后就不能再修改
contract ConstantImmutable{ string private constant name ="Thinkingchain"; uint private immutable age; constructor(uint256 _age){ age = _age; //age = 10; }
function getName() public pure returns(string memory){ return name; }
function getAge() public view returns(uint){ return age; } /* function setAge() public{ age++; } */ }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/546068.html
標籤:區塊鏈
上一篇:solidity注解標簽