1 Star 0 Fork 0

暗夜舞者/learn_solidity

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Test3.sol 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
huqibo 提交于 2021-08-17 10:56 . first commit
pragma solidity ^0.4.0;
contract C{
uint[] public data1;
uint[] public data2;
function appendOne() public {
append(data1);
}
function appendTwo() public {
append(data2);
}
function append(uint[] storage d) internal{
d.push(1);
}
function length1() public view returns(uint){
return data1.length;
}
function length2() public view returns(uint){
return data2.length;
}
//TypeError: Member "push" is not available in uint256[] memory outside of storage.
// function add(uint[] d) public {
// d.push(27);
// }
//Location has to be memory for publicly visible functions (remove the "storage" keyword).
// 有两种选择,防止随意的修改状态,方法不能对外公开
// 第一是可以把storage去掉,但去掉以后不能push
// 第二是保留storage,把public改为internal
// function add(uint[] storage d) public {
// d.push(27);
// }
function add(uint[] storage d) internal {
d.push(27);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hqbzl/learn_solidity.git
git@gitee.com:hqbzl/learn_solidity.git
hqbzl
learn_solidity
learn_solidity
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385