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; }
}
Add a comment
|
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()
.
-
-
it is giving me the following error: Type struct Mycontract.User memory is not implicitly convertible to expected type struct Mycontract.User storage pointer. User storage user= User("hey"); ^----------------------------^ – user61878 Jul 29 '20 at 8:44
-
-