繁体   English   中英

Memory 与不同类型数据的一致性

[英]Memory in solidity with different types of data

当创建一个接受 arguments 的 function 时,比如 int、uint、string 等等,为什么它需要指定该字符串是 memory,但是当传递一个 uint 时,它不需要指定它是一个 memory 示例:

contract SompleContract{
    string favWord;
    uint favNum;
// in here we have 2 arguments _favNum and _favWord but passing _favWord needs to be memory
    function simpleFunction(uint _favNum, string memory _favWord) public {
        favNum = _favNum;
        favWord = _favWord;
    }

}

为什么它必须是 memory 当它是一个字符串(在这种情况下是 _favWord)而不是当它是一个 uint(_favNum)以及必须指定哪种数据类型时它是 memory 当将它传递到 function 时

需要为所有引用类型指定数据位置( memorycalldata数据或storage )。 在 Solidity 中, string被视为动态大小的字节数组——而数组是一种引用类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM