Hi guys,
i'm always confused about array creation and array passing. For example, if I want to pass an array of size 36 to a function of a different contract (parameter: uint[36] memory arrayName), I try to pass myArray which is defined as:
uint[36] memory myArray = new uint[](36);
Unfortunately, this does not compile:
TypeError: Type uint256[] memory is not implicitly convertible to expected type uint256[36] memory.
--> contracts/Contract.sol:105:9:
|
105 | uint[36] memory myArray = new uint[](36);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I cannot figure out how to write that line. Can you help me please?

Aug 30, 2021, 1:55 PM
perhaps uint[] memory myArray = new uint[](36); ?
Aug 30, 2021, 3:05 PM
This only works if the other contract's function does not specify a size. But this one species the size to be 36. In this case, i get

TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256[] memory to uint256[36] memory requested.

in the line where i invoke the other contract's function

if i then try to make the "conversion" explicit via uint256[36](myArray), i get:

TypeError: Explicit type conversion not allowed from "uint256[] memory" to "uint256[36] memory".
Aug 30, 2021, 7:00 PM

© 2024 Draquery.com All rights reserved.