Ethereum Asked by user61878 on October 27, 2020
pragma solidity >=0.5.0 <0.7.0;
contract Mycontract{
uint256 a;
struct User
{ string name; }
User[] users;
function foo() public{
User storage user=users[0];
user.name="hey";
}
function get() public view returns(string memory)
{ return users[0].name; }
}
It is caused by this : User storage user=users[0];
You try to assign to user
the first element of the users
array but you can't access an empty array.
If you want to push your object into the array you can use array.push()
.
Correct answer by clement on October 27, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP