Remix
如何在solidity中返回固定長度的數組
我收到以下錯誤,如何解決?
Expected type name function Array_Data () public view returns (memory uint []) {^ ---- ^.
pragma solidity >=0.5.0 <0.6.0; contract Lock { uint[] public _gas_left; function closeAccount() public { _gas_left.push(gasleft()); } function Array_Data() public view returns(memory uint[]) { uint[] memory arrayOfgas = new uint[](20); for (uint i = 0; i < _gas_left.length; i++) arrayOfgas[i] = _gas_left[i]; return arrayOfgas; } }
如何解決?
這應該可以解決您的錯誤。
應該
returns(uint[] memory)
不是returns(memory unit[])
pragma solidity >=0.5.0 <0.6.0; contract Lock { uint[] public _gas_left; function closeAccount() public { _gas_left.push((gasleft())); } function Array_Data() public view returns(uint[] memory){ uint[] memory arrayOfgas = new uint[](20); for (uint i = 0; i < _gas_left.length; i++) arrayOfgas[i] = _gas_left[i]; return arrayOfgas; } }