9
二维数组存数值5000就报错
source link: https://learnblockchain.cn/question/2486
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
二维数组存数值5000就报错
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract Storage {
uint[5][7] levelParams = [
[200*1e18, 0, 18, 0, 40],
[400*1e18, 10, 20, 0, 40],
[800*1e18, 12, 22, 0, 40],
[1000*1e18, 14, 24, 0, 40],
[2000*1e18, 18, 28, 6, 50],
[3000*1e18, 20, 30, 8, 60],
[5000*1e18, 20, 30, 10, 70]
];
}
把 [5000*1e18, 20, 30, 10, 70] 中的5000改成4000又是正常
最佳答案 3天前
我还真没有遇到过这个问题。
根据报错“Unable to deduce common type for array elements”, 找到了这个: https://gitter.im/ethereum/solidity/archives/2018/03/18
发现下面的方式可以解决:
uint256[5][7] levelParams = [
[uint(200*1e18), 0, 18, 0, 40],
[uint(400*1e18), 10, 20, 0, 40],
[uint(800*1e18), 12, 22, 0, 40],
[uint(1000*1e18), 14, 24, 0, 40],
[uint(2000*1e18), 18, 28, 6, 50],
[uint(3000*1e18), 20, 30, 8, 60],
[uint(5000*1e18), 20, 30, 10, 70]
];
Tiny熊
- 布道者
擅长:智能合约,以太坊 | 采纳率 39% | 回答于 3天前
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK