【发布时间】:2021-12-15 03:53:54
【问题描述】:
我正在使用这个版本的solidity,pragma solidity >=0.4.22 <0.9.0;
每当我编译松露时,我都会得到这个TypeError: Member "length"。当我将版本更改为0.4.0 时,错误消失了,但我不能使用这个版本。我需要使用这个pragma solidity >=0.4.22 <0.9.0;
这是错误:
TypeError: Member "length" is read-only and cannot be used to resize arrays.
--> project:/contracts/Ballot1.sol:23:9:
|
23 | proposals.length = _numProposal;
| ^^^^^^^^^^^^^^^^
Compilation failed. See above.
【问题讨论】:
-
为什么不使用
slice来减少数组而不是更改长度属性?proposal = proposal.slice(0, _numProposal);。如果proposal被声明为 const 并且因此不可重新分配,则使用另一个变量名。